I'm sure the answer is a fairly simple regex pattern - but I seem to have difficulty with all the nuances of regex.
I'm looking for a regex to validate a repeating pattern of characters. The pattern is AAA-AAA where is any alphanumeric character ([A-Z0-9] - I'll be using strtoupper before the regex). This pattern could repeat any number of times from 1 (AAA) to infinity, but always in 3 alphanumeric character groups separated by a dash(-).
Incomplete patterns should not match (AAA-) or (AAA-AA).
Here is the regex I've come up with so far: /^([A-Z0-9]{3,}-?)*?$/
It appears to work so far, but incomplete patterns that look like (AAA-) in other words a valid set of alphanumeric characters ending with a dash still get a valid result.
Any regex gurus out there that can help with this?
Thanks.
I'm looking for a regex to validate a repeating pattern of characters. The pattern is AAA-AAA where is any alphanumeric character ([A-Z0-9] - I'll be using strtoupper before the regex). This pattern could repeat any number of times from 1 (AAA) to infinity, but always in 3 alphanumeric character groups separated by a dash(-).
Incomplete patterns should not match (AAA-) or (AAA-AA).
Here is the regex I've come up with so far: /^([A-Z0-9]{3,}-?)*?$/
It appears to work so far, but incomplete patterns that look like (AAA-) in other words a valid set of alphanumeric characters ending with a dash still get a valid result.
Any regex gurus out there that can help with this?
Thanks.