2016-01-07 31 views
0
Pattern p = Pattern.compile(".*\\\"(.*)\\\".*"); 
Matcher m = p.matcher("\"Hi there\"! How are you"); 
if (m.find()) { 
    try { 
     String iGotMyMatchedString = m.group(0); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

上面的代碼將返回字符串裏面的雙引號是「你好」。 我怎樣才能獲得remaininig字符串「!怎麼是你」從正則表達式中獲得無與倫比的字符串(Android)

回答

3

你不能得到無與倫比的字符串,而是可以通過調用您的匹配對象的group(2)使用捕獲組圍繞第二部分,並獲得它:

".*\\\"(.*)\\\"(.*)"