Reputation: 190
I am working on RegEx that will match a string that contains only uppercase letters and digits but not exact words ABC or XYZ or LMN.
^(?!ABC|XYZ|LMN)([A-Z0-9]+)$
This works for most of the cases but fails for input ABC12, XYZ8 etc.
How can I improve this to match the requirement.
I've referred RegEx to exclude a specific string constant but couldn't tackle this one.
Upvotes: 0
Views: 436
Reputation: 1375
If you are trying to match the whole string or line using ^ and $, then you can put the $ inside your negative lookahead. This will allow ABC12 to match.
^(?!(ABC|XYZ|LMN)$)([A-Z0-9]+)$
Upvotes: 1