[英]What's the meaning of `?:` in regular expression
I saw a regular expression to match a URL: /^\\/users?(?:\\/(\\d+)(?:\\.\\.(\\d+))?)?/
. 我看到一个匹配URL的正则表达式:/
/^\\/users?(?:\\/(\\d+)(?:\\.\\.(\\d+))?)?/
?(?: /^\\/users?(?:\\/(\\d+)(?:\\.\\.(\\d+))?)?/
?: /^\\/users?(?:\\/(\\d+)(?:\\.\\.(\\d+))?)?/
. /^\\/users?(?:\\/(\\d+)(?:\\.\\.(\\d+))?)?/
.( /^\\/users?(?:\\/(\\d+)(?:\\.\\.(\\d+))?)?/
。 I am confused by the usage of ?:
in the beginning of each group match. 我对每组比赛开始时使用
?:
感到困惑。
What's the meaning of that? 那是什么意思?
(?:)
(the ()
are part of the expression) is a non-capturing group . (?:)
( ()
是表达式的一部分) 是非捕获组 。
See http://www.regular-expressions.info/refadv.html . 见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 http://www.regular-expressions.info/refadv.html
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.
匹配括号内的正则表达式,但在执行匹配或稍后在模式中引用后,无法检索组匹配的子字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.