0

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.

ManjushaDC
  • 180
  • 3
  • 15

1 Answers1

1

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]+)$

Matt Miguel
  • 1,325
  • 3
  • 6