Reputation: 3414
How to give regular expression following numbers -
(state code 2 chars)-(sub code two digits)-(sub code 1 or 2 chars)-(number max 4 digits)
AP-05-BS-9853
KL-35-AC-638
OD-03-C-3843
I have tried this way. But not working
^[A-Z]{2}[ -][0-9]{1,2}(?: [A-Z])?(?: [A-Z]*)? [0-9]{1,4}$
Upvotes: 1
Views: 59
Reputation:
use group so that it will recognize it properly.
([a-zA-Z]{2}-\d{1,2}-[a-zA-Z]{1,2}-\d{3,4})
this is working 100%
demo : https://regex101.com/r/zZ3eT7/2
Upvotes: 1
Reputation: 521249
Try this regex:
^\w{2}-\d{2}-\w{1,2}-\d{1,4}$
Demo here:
Upvotes: 2