Recently, in the process of developing a pseudo-code translation tool, we encountered a problem in the pseudo-code using the spring El Rules, the non-variable is limited to ${"1"}, parsed according to the type of the context to the corresponding Java type. On the rule, we originally asked for OP1 op OP2 must have space between, but later found that there are still some places there is no space between operators and operands, in order to be as much as possible, we choose to judge according to the context, appropriate preprocessing so that subsequent parsing will not be error, The following processing is required:
Linetext.replaceall ("#\\+", "# +"). ReplaceAll ("\\[email protected]", "+ @"). ReplaceAll ("\\+\\$", "+ $")
But at the time of execution,
Exception in thread "main" java.lang.IllegalArgumentException:Illegal Group Reference:group Index is missing
At Java.util.regex.Matcher.appendReplacement (Unknown Source)
At Java.util.regex.Matcher.replaceAll (Unknown Source)
At Java.lang.String.replaceAll (Unknown Source)
After repeated checks, the second parameter of the ReplaceAll also needs to be escaped, as follows:
Linetext.replaceall ("#\\+", "# +"). ReplaceAll ("\\[email protected]", "+ @"). ReplaceAll ("\\+\\$", "+ \\$")
However, Javadoc does not mention this point.
Java ReplaceAll $ replacement