Say I have a collection of strings "123AB", "456CDEF", "789G", "012-HI". How do I find all the strings that are number(1 or more) followed by alpha(1 or more) with no special characters, where the alpha characters are not AB?
To clarify, the regex applied to the previous collection should yield "456CDEF" and "789G". "123AB" is ignored because the alpha value is AB and "012-HI" is ignored because it contains a non-alpha. The regex for what I'm looking for, minus the special AB rule, is ^[0-9]+[A-Z]+$
. Case is irrelevent. I've tried a few variations of the [^ ]
rule with no success, since all the patterns I came up with allowed special characters.
To generalize, how can I match a set of alpha values that don't match a certain subset of alpha values, using a single regex pattern?
Note: "123ABC" should be accepted as well. Only strings with AB exactly should be ignored.