Your regex will also match substrings, for example NA
and SA
when used on the string NASA
.
You will need to use word boundaries to prevent that from happening. Then, use a negative lookahead assertion to exclude SN
:
\b(?!SN)[A-Z]{2}\b
Edit: Oh, that Flex :)
Well, POSIX regex engines don't know lookarounds. You'll need to spell it out:
\b(S[A-MO-Z]|[A-RT-Z]N|[A-MO-RT-Z]{2})\b