[英]match numbers not prefixed with specific word by Regex
I want to extract the numbers that are not behind "A" by Regex. 我想提取Regex不在“ A”后面的数字。
For textA123text
, none should be matched because 123
is behind A
. 对于
textA123text
,因为123
在A
后面,所以都不应该匹配。
For textBC123text
, 123
should be matched. 对于
textBC123text
,应匹配123
。
I found negative lookbehind like (?<!A)(\\d)
does not work. 我发现像
(?<!A)(\\d)
一样的负向后方不起作用。 It matches 23
in textA123text
because 23
is behind 1
. 它匹配
textA123text
中的23
,因为23
在1
后面。
Is there any way to do this by using Regex? 有没有办法通过使用正则表达式来做到这一点?
In addition to using negative lookbehind for A
, also negative lookbehind for \\d
, to ensure that you're at the first character in a number, which is not preceeded by A
: 除了对
A
使用负向后看之外,对\\d
也使用负向后看,以确保您位于数字中的第一个字符,而不是A
开头:
(?<![A\d])\d+
https://regex101.com/r/jhWM30/1 https://regex101.com/r/jhWM30/1
当然,只需在您的后置断言中添加\\d
即可:
(?<![A\d])(\d+)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.