Reputation: 83
I need to write a regex to capture all numbers being at least 9 digits and not preceded by REQ or INC substrings.
Some examples of what I want:
1234567890 -> match -> 1234567890
INC1234567890 -> not matching
REQ1234567890 -> not matching
IN1234567890 -> match -> 1234567890
What I tried so far:
(?<!(?:REQ|INC))(\d{9,})
But then my results are the following:
1234567890 -> match -> 1234567890
INC1234567890 -> match -> 234567890
REQ1234567890 -> match -> 234567890
IN1234567890 -> match -> 1234567890
I tried playing around with \b
but did not achieve anything.
Upvotes: 2
Views: 46
Reputation: 626738
You can use
(?<!REQ|INC|\d)\d{9,}
See the regex demo
Details
(?<!REQ|INC|\d)
- no REQ
, INC
or digit allowed immediately on the left\d{9,}
- nine or more digits.Upvotes: 1