【发布时间】:2016-06-08 07:28:58
【问题描述】:
我有这个正则表达式字符串..
String regex = ^(/|\\){2}(projects|depot|perforce_[0-9a-zA-Z]+)(\\1)q(uality|a)]+)(\\1)$
应与此正则表达式匹配的字符串测试用例:
- //仓库/质量/
- \\projects\qa\
- //perforce_0tests001/quality/
这个正则表达式的解释:
- 比赛开始
- group1: / or \(只有两次)
- group2: depot or 项目 or perforce_xn 其中 xn 是任何数字或字母
- group3:仅引用 group1 一次
- q
- group4: 实体或 a
- group5:仅引用 group1 一次
- 比赛结束
这个正则表达式失败,出现以下字符串异常 //depot/quality/
java.util.regex.PatternSyntaxException: Unclosed group near index 64
^(/|\){2}(projects|depot|perforce_[0-9a-zA-Z]+)(\1)q(uality|a)(\1)$
^
我的另一个问题是我还想在 group1 中允许竖线字符:|
这样下面的字符串也匹配:||depot|quality|
我该怎么做?不知道怎么逃?
【问题讨论】: