不包括两个单词的搜索-匹配/单词/但不是/一个单词/。

时间:2022-09-13 09:19:18

Update to my previous question - How could I modify the search string suggested to me by @coldspeed so that it also excludes uses such as a great game? I should have thought about that earlier, sorry. If someone could help me out again, it would be great. thanks

I need to search my corpus for the word game but I would like to specify the search to exclude one of the uses of the word: a game. So actually I need to exclude the string a+space+game

我需要在我的语料库中搜索“game”这个词,但是我想指定搜索,以排除“game”这个词的一个用法。实际上我需要排除字符串a+空格+游戏

I was trying to compose the regex search string, but unsuccessfully: \bgame\b^(?!.*?[a gam]).*

我试图写正则表达式搜索字符串,但失败:\ bgame \ b ^(? !。* ?(gam))。*

I'm sorry if I'm asking a question that has already been answered before. The thing is I'm not sure what to look for to get the answer.

如果我问的问题之前已经有人回答过,我很抱歉。问题是我不知道该找什么来得到答案。

1 个解决方案

#1


3  

game that is not preceded by a_? You can use a negative lookbehind.

游戏之前没有a_?你可以使用负面的外观。

(?<!a\s)game

Demo: https://regex101.com/r/2PQi1B/2

演示:https://regex101.com/r/2PQi1B/2

A more accurate version of this as suggested by Wiktor Stribiżew (to explicitly match word boundaries for edge cases):

这所显示的更准确版本有意Stribiżew(显式匹配单词边界边界情况):

r'(?<!\ba\s)\bgame\b 

#1


3  

game that is not preceded by a_? You can use a negative lookbehind.

游戏之前没有a_?你可以使用负面的外观。

(?<!a\s)game

Demo: https://regex101.com/r/2PQi1B/2

演示:https://regex101.com/r/2PQi1B/2

A more accurate version of this as suggested by Wiktor Stribiżew (to explicitly match word boundaries for edge cases):

这所显示的更准确版本有意Stribiżew(显式匹配单词边界边界情况):

r'(?<!\ba\s)\bgame\b