You may use a "spelled-out" regex approach where you list all possible variations in a grouping construct with alternation operators:
^(?:[a-zA-Z][0-9]|[0-9][a-zA-Z]|[a-zA-Z]{2})[0-9]{6}$
Or, if your regex engine supports lookaheads
^(?![0-9]{2})[0-9a-zA-Z]{2}[0-9]{6}$
See the first regex demo and the second regex demo.
The ^
asserts the position at the start of the string, then the (?:[a-zA-Z][0-9]|[0-9][a-zA-Z]|[a-zA-Z]{2})
non-capturing group matches a letter + digit, digit + letter or just two letters. Then, [0-9]{6}
matches 6 digits up to the end of the string ($
).
The second regex matches the start of a string (^
), then fails the match if the first two chars are digits ((?![0-9]{2})
), then matches two alphnumeric chars ([0-9A-Za-z]{2}
) and then six digits ([0-9]{6}
), and asserts the position at the end of the string ($
).