Hello Shem,
Can anyone assis me in creating a regex for the following formats
AA.
AA.A
AAA
AAAA
A denotes alpha characters only
These are all very simple formats. You should be able to figure it ot quite
easily. Regardless here's how I'd do it:
^(?i:[a-z]{2}(?:\.[a-z]?|[a-z]{1,2}))$
I'll explain:
^ beginning of teh string
(?i:....) case insensitive matching within the parenthesis
[a-z]{2} first two alphanumeric characters (all formats begin with two characters)
(?:...) non-capturing group, is faster than just (...)
\.[a-z]? escape the . as it's a special character in regex followed by an
optional character (first two formats are now satisfied)
| OR....
[a-z]{1,2} one or two more characters (the thrid and fourth are now also
satisfied)
$ end of the input.
Kind regards,
Jess