让正则表达式查找缺失的词
Have Regex Find Absent Word
在此示例中,我需要查找以 @ 开头且在下一个 @ 之前没有单词“关键字”的条目:
@something
something
something
keyword
something
something
@something
something
something
something
something
@something
something
something
keyword
something
something
所以这个搜索字符串会指向第二个例子。有人知道如何使用 Regex 执行此操作吗?
以下正则表达式似乎有效:
@\w+(?![^@]*\bkeyword\b[^@]*)
解释:
@\w+ match a @label
(?! provided that we DON'T see ahead
[^@]* any text without another @label
\bkeyword\b which also has the "keyword"
)
在此示例中,我需要查找以 @ 开头且在下一个 @ 之前没有单词“关键字”的条目:
@something
something
something
keyword
something
something
@something
something
something
something
something
@something
something
something
keyword
something
something
所以这个搜索字符串会指向第二个例子。有人知道如何使用 Regex 执行此操作吗?
以下正则表达式似乎有效:
@\w+(?![^@]*\bkeyword\b[^@]*)
解释:
@\w+ match a @label
(?! provided that we DON'T see ahead
[^@]* any text without another @label
\bkeyword\b which also has the "keyword"
)