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.
我看到一个正则表达式匹配一个URL:/ ^ \ /用户?(?:\ /(\ d +)(?:\ \。(\ d +))吗?)?。我被什么用法搞糊涂了?:在每组比赛开始的时候。
What's the meaning of that?
这是什么意思?
3 个解决方案
#1
10
(?:)
(the ()
are part of the expression) is a non-capturing group.
(?:) (the()是表达式的一部分)是一个非捕获组。
See http://www.regular-expressions.info/refadv.html.
见http://www.regular-expressions.info/refadv.html。
#2
5
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
http://www.regular-expressions.info/refadv.html
#3
1
Read through: http://docs.python.org/library/re.html
阅读: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.
普通圆括号的非捕获版本。匹配括号内的任何正则表达式,但是在执行匹配或稍后在模式中引用之后,无法检索组匹配的子字符串。
#1
10
(?:)
(the ()
are part of the expression) is a non-capturing group.
(?:) (the()是表达式的一部分)是一个非捕获组。
See http://www.regular-expressions.info/refadv.html.
见http://www.regular-expressions.info/refadv.html。
#2
5
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
http://www.regular-expressions.info/refadv.html
#3
1
Read through: http://docs.python.org/library/re.html
阅读: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.
普通圆括号的非捕获版本。匹配括号内的任何正则表达式,但是在执行匹配或稍后在模式中引用之后,无法检索组匹配的子字符串。