The classic way would be:
(?:[0-9]{2}|[0-9]{6})[A-z]{4}
[Literally as [0-9]{2}
OR [0-9]{6}
]
But you can also use this one, which should be a little more efficient than the above with less potential backtracking:
[0-9]{2}(?:[0-9]{4})?[A-z]{4}
[Here, [0-9]{2}
then potential other 4 [0-9]
which makes a total of 6 [0-9]
in the required conditions]
You might not be aware that [A-z]
matches letters and some other characters, but it actually does.
The range [A-z]
effectively is equivalent to:
[A-Z\[\\\]^_`a-z]
Notice that the additional characters that match are:
[ \ ] ^ _ `
[spaces included voluntarily for separation but is not part of the characters]
This is because those characters are between the block letters and lowercase letters in the unicode table.
[A-z]
IN A REGEX. To match any ASCII letter, uppercase or lowercase, use[A-Za-z]
.[A-z]
matches all those, plus several punctuation characters whose code points happen to lie betweenZ
anda
.[A-z]
is not part of my regex I'm working with, I just used it as a stand in for the other parts of my lengthy regex so as to not detract from my question. Thank you for the teaching moment, however (no sarcasm, I actually am new-ish to regex and didn't realize this).