简体   繁体   中英

match numbers not prefixed with specific word by Regex

I want to extract the numbers that are not behind "A" by Regex.

For textA123text , none should be matched because 123 is behind A .

For textBC123text , 123 should be matched.

I found negative lookbehind like (?<!A)(\\d) does not work. It matches 23 in textA123text because 23 is behind 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])\d+

https://regex101.com/r/jhWM30/1

当然,只需在您的后置断言中添加\\d即可:

(?<![A\d])(\d+)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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