Reputation: 59
string:
"Btw-nummer: NL855162508B01 NL855162508B02 "
Regex code used:
(^((?!NL855162508B01).))([A-Za-z]{2}\d{9}[A-Za-z]\d{2})
Regex do not match: NL855162508B01
But do match: NL855162508B02
As seen in this Regexr I have used: https://regexr.com/5im28
Desired behavior: match NL855162508B02
Can you guys help?
Upvotes: 1
Views: 64
Reputation: 163632
You were almost there, but this part (?!NL855162508B01).
first matches any character except a newline due to the .
You are using 3 capturing groups, which can all be omitted if you need a match only.
To also match the string when it is not directly at the start, you can omit the anchor ^
and use word boundaries \b
\b(?!NL855162508B01\b)[A-Za-z]{2}\d{9}[A-Za-z]\d{2}\b
Upvotes: 2