3

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

1
  • 3
    You can prepend a word boundary and match the digits \b(?!0[1-9][0-9]{5})\d+ regex101.com/r/8HhsS8/1 Commented Sep 21, 2020 at 23:10

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

So I tried this with a long string today and it did not take: 0221547 02556 02662933434343423423423423505 0565 05 any suggestions... NVM I added a \s in the selector and it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.