What will be the best regular expression if I want to intake alphanumerics, ‘-‘ and ‘+’ signs.
e.g. LA2+4 or td1-23
What will be the best regular expression if I want to intake alphanumerics, ‘-‘
Share
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.
No magic involved, just specify that your complete string (
^...$) must match a sequence of arbitrary length (...*) of alternatively ([...]) upper-case letters (A-Z), lower-case letters (a-z), digits (0-9), the plus sign (+) and the minus sign (-).The only special case to consider is the fact that the minus sign you want to accept (
-) must appear as the last (or first) letter in the option group, since the same character is also used to specify ranges (as inA-Z).So, the solution is: