简体   繁体   English

匹配未由Regex加上特定单词前缀的数字

[英]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 ,因为123A后面,所以都不应该匹配。

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 ,因为231后面。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM