I’m trying to match a string using regex (of which I am new to) but I can’t get it to match.
These should be accepted:
- GT-00-TRE
- KK-10-HUH
- JU-05-OPR
These should not:
- HTH-00-AS
- HM-99-ASD
- NM-05-AK
So the pattern goes 2 letters, hyphen, 2 digits (between 00 and 11 inclusive), hyphen, 3 letters.
So far the best I can come up with is:
var thePattern = /^[a-z]{2}[-][00-11][-][a-z]{3}$/gi;
I can’t help but feel that I’m pretty close.
Can anyone give me any pointers?
Thanks.
This should be what you need:
In order to do a range 00-11, you have to say “(0 followed by 0-9) or (1 followed by 0 or 1)”. This is because specifying a range within
[]only works for single digits. Luckily your case is pretty simple, otherwise it could get quite complex to work around that.