Regex pattern error in Android when matching closing brace

Viewed 1822

I am using java.util.regex.Pattern class to match a string in a Android program.

if(Pattern.matches("\\{\\{.*?}}", element.getValue())) {
   ...             
} else {
   ...
}

And I got the following error.

 Caused by: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 8
                                                                  \{\{.*?}}

I am using Android studio and Open JDK. To test the regex expression I wrote a simple program in Netbeans and it works fine. Netbeans also use openjdk.

System.out.println(Pattern.matches("\\{\\{.*?}}", "{{hello:sdf}}"));

Why the regular expression is giving an error in android project?

1 Answers
Related