我的正则表达式如下:
(?<![\s]*?(\"|")")WORD(?![\s]*?(\"|"))
正如您所看到的,我正在尝试匹配除了在“引号”内的所有单词。所以...
WORD <- Find this
"WORD" <- Don't find this
" WORD " <- Also don't find this, even though not touching against marks
"WORD" <- Dont find this (I check " and " so works after htmlspecialchars)
我相信我的正则表达式是完美的,如果我没有收到以下错误:
Compilation failed: lookbehind assertion is not fixed length
考虑到回溯限制,是否有其他方法可以实现我的意图?
如果你能想到其他的方法,请告诉我。
非常感谢,
马修
附言:WORD部分将实际包含Jon Grubers URL检测器。
(?<!("|")\s*)WORD(?![\s]*(\"|"))
。没有必要使空格捕获变得懒惰,并且你在回顾中翻转了空格/引号术语。 - FrankieTheKneeMan