我已经尝试了几个小时来解决这个问题。假设有一个字符串
"hello Exclude1 4:32 test test Exclude2 5:23 hello 2:19 some more text 42:3 more text"
我正在尝试创建一个仅匹配但
忽略2:19
和42:3
Exclude1 4:32
Exclude2 5:23
即如果 4:32 或 n:nn 前面有 Exclude1 或 Exclude2,则不匹配。谢谢
我已经尝试了几个小时来解决这个问题。假设有一个字符串
"hello Exclude1 4:32 test test Exclude2 5:23 hello 2:19 some more text 42:3 more text"
我正在尝试创建一个仅匹配但
忽略2:19
和42:3
Exclude1 4:32
Exclude2 5:23
即如果 4:32 或 n:nn 前面有 Exclude1 或 Exclude2,则不匹配。谢谢
您可以使用否定的lookbehind来忽略某个其他表达式之前的表达式:
(?<!Exclude1 )(?<!Exclude2 )\d+:\d+
这将匹配##:##
没有立即出现在Exclude1
或之前的那个Exclude2
。
(?<!a)b for example matches b which is not preceded by a, you can
easily adapt it to your needs.
您是否尝试过类似的方法:
(?<!Exclude\d )\d+:\d+