简体   繁体   中英

regex negative lookahead using javascript

And thanks for your help!

I am trying to do an negative inclusion

I have the following: 0[1-9][0-9]{5} this works for positive inclusion against this:
0258714 0465666 1213655 568464668 225 75487 021523 56556 0236589

but when I try this

(?!0[1-9][0-9]{5})

it doesn't include the opposite
0258714 0465666 1213655 568464668 225 75487 021523 56556 0236589

How could we get this to work?

see link for setup: https://regex101.com/r/OkMliM/1

The lookahead by itself is unanchored and will match all the positions where the assertion is true.

What you can do is use a word boundary followed by the assertion. If it is true, then match 1 or more digits.

\b(?!0[1-9][0-9]{5}\s)\d+

See a regex demo

added an \s to make it work

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