我尝试匹配单词只有当要比较的单词和字符串是单引号时才这样:
foo foo #match
'foo' foo #don't match
foo 'foo' #don't match
'foo' 'foo' #match
foo 'foo #match
foo foo' #match
我试过这个正则表达式:
((?<!')|((\')?))foo((?!')|(\W*))(?=\W\s*|$)
但输出是:
foo foo #match it's good
'foo' foo #don't match it's good
foo 'foo' #match it's not good
foo 'foo #match it's good
foo foo' #match it's good
'foo' 'foo' #match it's good
此外,如果我尝试使用这封信,所有带有此字母的字词都匹配我不想要,但如果我添加\b
所有正则表达式都不起作用...
答案 0 :(得分:0)