Home > Software design >  Regular expresion two or three digits and consequently allow only one or two letters
Regular expresion two or three digits and consequently allow only one or two letters

Time:10-14

I'm trying to write a regular expression that, if I write two digits, only allows two letters, but if I write three numbers, only allows one letter

123A --> OK
12AB--> OK
AAAA-> KO
1234--> KO
1AAA-> KO
A111-> KO
123AB --> KO

Thi is the reg I have right now

(\d{2,3})([a-zA-Z]{1,2})?$

that I'm trying in enter image description here

Demo: https://regex101.com/r/l7XjNy/1

  • Related