public static String escapeAssertion ( String s ) { //Replace the first dot, because the string doesn't start with "m=" // and is not covered by the regex. if ( s . startsWith ( "r" ) || s . startsWith ( "p" ) ) { s = s . replaceFirst ( "\\." , "_" ) ; } String regex = "(\\|| |=|\\)|\\(|&|<|>|,|\\+|-|!|\\*|\\/)(r|p)\\." ; Pattern p = Pattern . compile ( regex ) ; Matcher m = p . matcher ( s ) ; StringBuffer sb = new StringBuffer ( ) ; while ( m . find ( ) ) { m . appendReplacement ( sb , m . group ( ) . replace ( "." , "_" ) ) ; } m . appendTail ( sb ) ; return sb . toString ( ) ; }
escapeAssertion escapes the dots in the assertion because the expression evaluation doesn t support such variable names .