I saw a regular expression to match a URL: /^\/users?(?:\/(\d+)(?:\.\.(\d+))?)?/
. I am confused by the usage of ?:
in the beginning of each group match.
What's the meaning of that?
It indicates that the subpattern is a non-capture subpattern. That means whatever is matched in (?:\w+\s) , even though it's enclosed by () it won't appear in the list of matches, only (\w+) will.
[] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9. (a-z0-9) -- Explicit capture of a-z0-9 .
(?:)
(the ()
are part of the expression) is a non-capturing group.
See http://www.regular-expressions.info/refadv.html.
It's a non-capturing group, so if a match is made that particular group will not be captured.
http://www.regular-expressions.info/refadv.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With