在 RE2 语法中否定匹配?
Negate match in RE2 syntax?
如何在 RE2 中为 "match strings not starting with 4 or 5" 编写正则表达式?
在 PCRE 中我会使用 ^(?!4)
但 RE2 doesn't support that syntax.
您可以使用这个正则表达式:
^[^45]
^
匹配开始,[^45]
匹配除 4
或 5
以外的任何内容。
我也遇到了这个问题,但我要查找的是单词字符串,而不是单个字符。
我的做法是多看两眼。
首先,找到所有匹配的项目,然后过滤它们以获得最终答案
例子
- 测试数据
aaabaraaa
aaafooaaa
aaazooaaa
aaaqooaaa
假设我想找到中心文本(在“aaa”之间),它不应该是“bar”或“foo”
使用 PCRE 很容易1 => https://regex101.com/r/nJcbt1/1/
使用re2我会选择分而治之:先用组缩小范围,再过滤。
如何在 RE2 中为 "match strings not starting with 4 or 5" 编写正则表达式?
在 PCRE 中我会使用 ^(?!4)
但 RE2 doesn't support that syntax.
您可以使用这个正则表达式:
^[^45]
^
匹配开始,[^45]
匹配除 4
或 5
以外的任何内容。
我也遇到了这个问题,但我要查找的是单词字符串,而不是单个字符。
我的做法是多看两眼。
首先,找到所有匹配的项目,然后过滤它们以获得最终答案
例子
- 测试数据
假设我想找到中心文本(在“aaa”之间),它不应该是“bar”或“foo”aaabaraaa aaafooaaa aaazooaaa aaaqooaaa
使用 PCRE 很容易1 => https://regex101.com/r/nJcbt1/1/
使用re2我会选择分而治之:先用组缩小范围,再过滤。