Reputation: 95
I'm running this code block in java ide i.e. intellij idea it is working fine and also tried some online regex matcher there it also working but when i run this in android studio it is showing error block of code is
public static String gettime(String temp){
String result = new String();
String time=new String();
time = ".*([0-1][0-9][:][0-5][0-9][:][0-5][0-9]).*";
Pattern pattern = Pattern.compile(time);//error during compilation
Matcher matcher = pattern.matcher(temp);
if(matcher.matches()){
result = matcher.group(1);
}
return result;
}
and the error is
java.util.regex.PatternSyntaxException: U_ILLEGAL_ARGUMENT_ERROR
.*([0-1][0-9][:][0-5][0-9][:][0-5][0-9]).*
Upvotes: 0
Views: 295
Reputation: 49986
It works if you switch from [:]
to :
time = ".*([0-1][0-9]:[0-5][0-9]:[0-5][0-9]).*";
escaping also works:
time = ".*([0-1][0-9][\\:][0-5][0-9][\\:][0-5][0-9]).*";
not sure why android does not like [:]
but it should be the same as :
Upvotes: 1