Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PatternSyntaxException: Unknown inline modifier near index N

807606May 23 2007 — edited May 23 2007
Exception in thread "main" java.util.regex.PatternSyntaxException: Unknown inline modifier near index 10
(\(+\(*((?\-?[0-9]+\.?[0-9]*)|@)(?\)*([\^\*/%\+\-_])\(*((?\-?[0-9]+\.?[0-9]*)|@)\)*)+\)+)
          ^
As you may have noticed, this is a pattern designed to match any mathematical expression. To make it a bit easier to read, here are my applicable pattern constants:
private static final String all = "([\\^\\*/%\\+\\-_])",
                          numbers = "((?\\-?[0-9]+\\.?[0-9]*)|@)";
and Matcher declaration:
Matcher m = Pattern.compile("(\\(+\\(*" + numbers + "(?\\)*"
                             + all + "\\(*" + numbers
                             "\\)*)+\\)+)").matcher(expression);
As '-' is used in Pattern to specify ranges, it seems to me that "\\-" should compile into a literal '-'. When I delete "\\", the same exception is thrown for '?':
Exception in thread "main" java.util.regex.PatternSyntaxException: Unknown inline modifier near index 11
(\(+\(*((?-?[0-9]+\.?[0-9]*)|@)(?\)*([\^\*/%\+\-_])\(*((?-?[0-9]+\.?[0-9]*)|@)\)*)+\)+)
           ^
What am I not seeing?

Message was edited by:
Jesdisciple
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 20 2007
Added on May 23 2007
10 comments
1,359 views