java regex to match word of varying length -
java.util.regex.PatternSyntaxException: Unclosed character class near
index
Was having trouble compiling the following regular expression, escaped for
java.lang.String
\\w{1,4}
Throws the following excepton
java.util.regex.PatternSyntaxException: Unclosed counted closure near index 4
\w{1
^
Obviously, the comma is breaking the expression and the following compiles
just fine
\\w{1\,4}
Notice the only difference in the second one, that works, the comma is
escaped with backslash - BUT- best I know, commas do NOT need to be
escaped in either java.lang.String or java regular expressions.
Reference:
http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html
What gives?
No comments:
Post a Comment