【发布时间】:2012-07-16 20:50:04
【问题描述】:
我有以下 Java 正则表达式,不是我写的,我正在尝试修改:
^class-map(?:(\\s+match-all)|(\\s+match-any))?(\\s+[\\x21-\\x7e]{1,40})$
^ ^
类似于this one。
注意第一个问号。这是否意味着该组是可选的?对应的)后面已经多了一个问号。正则表达式中的冒号有特殊含义吗?
正则表达式编译良好,并且已经有 JUnit 测试显示它是如何工作的。只是我有点疑惑为什么第一个问号和冒号会出现。
【问题讨论】:
-
The question mark and the colon after the opening round bracket are the special syntax that you can use to tell the regex engine that this pair of brackets should not create a backreference。 regular-expressions.info/brackets.html