Regex编译intellij idea,但不是在android工作室和显示



我在java ide中运行这个代码块,即intelllij idea它工作得很好,并且还尝试了一些在线正则表达式匹配器,它也在工作但是当我在android studio中运行这个程序时它显示的错误代码块是

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;
}

,错误是

java.util.regex.PatternSyntaxException: U_ILLEGAL_ARGUMENT_ERROR
.*([0-1][0-9][:][0-5][0-9][:][0-5][0-9]).*

如果从[:]切换到:

time = ".*([0-1][0-9]:[0-5][0-9]:[0-5][0-9]).*";

转义也可以:

time = ".*([0-1][0-9][\:][0-5][0-9][\:][0-5][0-9]).*";

不知道为什么android不喜欢[:],但它应该和:一样

最新更新