0

使用此正则表达式时会引发以下异常[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 文件中读取此内容。

4

2 回答 2

3

你可能想要这个:

[0-9]+_[0-9]+_[0-9]+(_[0-9]+)?
于 2013-02-12T13:17:07.787 回答
0

你必须用反斜杠转义逗号:

[0-9]+_[0-9]+_[0-9]+(_[0-9]+){0\,1}
于 2018-03-01T15:14:29.800 回答