使用此[0-9]+_[0-9]+_[0-9]+(_[0-9]+){0,1}
正则表达式时会引发以下异常。
Caused by: java.util.regex.PatternSyntaxException: Unclosed counted closure near index 31
[0-9]+_[0-9]+_[0-9]+(_[0-9]+){0
^
at java.util.regex.Pattern.error(Pattern.java:1713)
at java.util.regex.Pattern.closure(Pattern.java:2759)
at java.util.regex.Pattern.group0(Pattern.java:2537)
at java.util.regex.Pattern.sequence(Pattern.java:1806)
at java.util.regex.Pattern.expr(Pattern.java:1752)
at java.util.regex.Pattern.compile(Pattern.java:1460)
at java.util.regex.Pattern.<init>(Pattern.java:1133)
at java.util.regex.Pattern.compile(Pattern.java:823)
我是从XML文件中读到的。
答案 0 :(得分:3)
你可能想要这个:
[0-9]+_[0-9]+_[0-9]+(_[0-9]+)?
答案 1 :(得分:0)
你必须用反斜杠转义逗号:
[0-9]+_[0-9]+_[0-9]+(_[0-9]+){0\,1}