I've been looking for a regex to match a string that either starts with a D or an E followed 2 or 3 digits. I'm pretty terrible at writing regex but this is what I tried: ^[DE]{1}[0-9]{1,2}$
Thank you
+: one or more ( 1+ ), e.g., [0-9]+ matches one or more digits such as '123' , '000' . *: zero or more ( 0+ ), e.g., [0-9]* matches zero or more digits. It accepts all those in [0-9]+ plus the empty string.
You can use regex (. *\d)([A-Z])(\d. *) - This will give you exact ONE Alphabet between numbers.
With regex you have a couple of options to match a digit. You can use a number from 0 to 9 to match a single choice. Or you can match a range of digits with a character group e.g. [4-9]. If the character group allows any digit (i.e. [0-9]), it can be replaced with a shorthand (\d).
Matches pattern anywhere in the name. Marks the next character as either a special character, a literal, a back reference, or an octal escape. For example, 'd' matches the character "d". ' \d' matches a digit character.
starts with D or an E followed by 2 or 3 digits
You're close. Try this regex:
^[DE][0-9]{2,3}$
You don't need {1}
as that is by default true and digits should be {2,3}
instead of {1,2}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With