我正在提取一串3到6个数字的字符串。但是,我不想包括一个连续超过3个0的数字。
现在我得到的是一个常规的前瞻性,但是如何实现零部分呢?
(\d{3,6})[:|\s]{0,2}([a-zA-Z]{3})((?:(?!\d{3,6}).)*)示例输入:
010113 tee Some text for a 1000 reasons 020113 mee More text所以输入是[3-6 numbers] [3 letter identifier] [message]格式的(重复)
我需要它来匹配字符串直到020113,而不仅仅是1000。
发布于 2014-03-19 09:14:35
您可以嵌套前瞻性断言:
((?:(?!(?!\d*000)\d{3,6}).)*)解释:
( # Match/capture in group 1:
(?: # Start of non-capturing group.
(?! # Assert that it's impossible to match...
(?!\d*000) # (unless it's a number that contains 000)
\d{3,6} # a number of three to six digits here.
) # End of lookahead
. # Match any character
)* # End of non-capturing group, repeat any number of times
) # End of capturing group 1看吧,在regex101.com上直播。
https://stackoverflow.com/questions/22500719
复制相似问题