I need regex for a line that starts with two characters followed by 2-4 digits or 2-4 digits followed by “-” and followed by 2-4 digits.
Examples:
- AB125
- AC123-25
- BT1-2535
Seems simple , but I got stuck with it …
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Regular expressions always seem simple, right up to the point where you try to use them 🙂
This particular one can be done with something along the lines of:
That’s:
That last one,
BT1-2535, doesn’t match your textual specification by the way since it only has one digit before the hyphen. I’m assuming that was a typo. You will also have to change the character bit to use[A-Za-z]if you want to allow lowercase as well.