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?
if (element.getValue().matches("\\{\\{.*?}}")), try also escaping}s if you still have issues.java.util.regexmatcher does not work correctly. It is better to rather usecom.google.code.regexp