1

The following exception is thrown when this [0-9]+_[0-9]+_[0-9]+(_[0-9]+){0,1} regex is used.

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)

I am reading this from a XML File.

2
  • 2
    show the piece of code you use Commented Feb 12, 2013 at 13:20
  • I use Java Standard Pattern.compile and Pattern.matcher in the code. Commented Feb 12, 2013 at 13:34

2 Answers 2

3

You probably want this:

[0-9]+_[0-9]+_[0-9]+(_[0-9]+)?
Sign up to request clarification or add additional context in comments.

2 Comments

But the same pattern works in this regexplanet.com/advanced/java/index.html
can you give some examples of what you need to match? Your supplied regex compiles fine, you may have an extra character somewhere in your string. post the code :)
0

You have to escape commas with backslash:

[0-9]+_[0-9]+_[0-9]+(_[0-9]+){0\,1}

1 Comment

You don't have to escape comma's with backslash in Java regex expressions. An expression like this works: "^(\\d+\\.){0,2}\\d+$". See also the discussion on backslash, escapes and quoting in the Javadoc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.