I need some help on a REGEX in php (Symfony).
I want to match values 1 to 60 or string all.
For number I’ve use this : ^([1-5]?[0-9]|60) but It match 0 … And I don’t now how can match “all”.
Can you help me ?
Many thanks before
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.
You should be able to divide it into possibilities as follows:
This gives you four possibilities:
[1-9]the single-digit values.[1-5][0-9]: everything from ten to fifty-nine.60: sixty.all: your “all” option.But keep in mind that regular expressions are not always the answer to every question.
Sometimes they’re less useful for complicated value checks (though, in this case, it’s a fairly simple one). Something like the following (pseudo-code):
can sometimes be, while more verbose, also more readable and maintainable.