colou?r matches color and colour
but what does the following ? do?
(first group)(second group)?(third group)
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.
It is a quantifier which means “zero or one”. It applies to the atom preceding it, therefore, here, the
u.It is one of the numerous regex metacharacters, which means, if you want to match a literal question mark, you’ll have to escape it (as in
\?), except in a character class.As to your second example:
it has exactly the same meaning. The grouping operator,
(...), apart from allowing backreferences, also has the nice effect to turn anything into parens into an atom.Which means, here, the text matched by the regex
second groupcan appear 0 or 1 time, similarly to theuinColou?r.http://www.regular-expressions.info/reference.html