我有一个用例,我正在字符串中搜索特定的子字符串,如果该特定字符串包含另一个特定的子字符串,我希望它被拒绝。
前任:
pikachu_is_the_best_ever_in_the_world_go_pikachu
mew_is_the_best_ever_in_the_world_go_mew
raichu_is_the_best_ever_in_the_world_go_raichu
我希望我的正则表达式能够选取包含单词“best”而不是单词“mew”的字符串,即第一个和第三个字符串。
我尝试将^(.*best).*$
和组合^((?!mew).)*$
到下面的表达式中,第二个正则表达式仅忽略字符串开头存在“mew”的单词。
^(.*best)((?!mew).).*$
Run Code Online (Sandbox Code Playgroud)
并且已经尝试过
^((?!mew).)(.*best).*$
Run Code Online (Sandbox Code Playgroud) regex ×1