Reputation: 9298
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?
Upvotes: 8
Views: 4889
Reputation: 66739
Read through: http://docs.python.org/library/re.html
(?:...)
A non-capturing version of regular parentheses. Matches whatever regular expression is inside the parentheses, but the substring matched by the group cannot be retrieved after performing a match or referenced later in the pattern.
Upvotes: 1
Reputation: 522597
(?:)
(the ()
are part of the expression) is a non-capturing group.
See http://www.regular-expressions.info/refadv.html.
Upvotes: 10
Reputation: 20270
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
Upvotes: 5