[英]regex compiling in intellij idea but not in android studio and showing
我在java ide中運行此代碼塊,即intellij的想法,它工作正常,還嘗試了一些在線正則表達式匹配器,它也可以工作,但是當我在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不喜歡[:]
但是應該與:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.