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