Is there something in regex to match (conditionally) only if it exists ?
e.g.
the string maybe
question_1
or only
question
In case of the former, it should match the integer in the end, but as in the case of the latter, it should leave 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.
The
?is the 0-1 quantifier in Regexes.\d?means 0 or 1 digit. The*is the 0-infinite quantifier.\d*means 0 or more digits. Is it what you want?(additionally the
+is the 1 or more quantifier, and not quantifier means exactly 1)To elaborate on what you asked, I would say
questionfollowed by an optional (_AND 1 or more digits)Where the brackets are only to group the sub expression (they are “mathematical” brackets)