提取字符串的樣本源代碼以匹配是正則表達式來從Java代碼
String string="welcome";
String k="a\"welcome";
我使用在Java "(\"[^(\")]*\")"
正則表達式。
但這提取
0:"welcome"
0:"a\"
預計產量
0:"welcome"
0:"a\"welcome"
我應該在正則表達式什麼變化,以獲得預期的輸出?
Java源:
private static String pattern1="(\"[^(\")]*\")";
public void getStrings(){
Pattern r = Pattern.compile(pattern1);
Matcher m = r.matcher("String string=\"welcome\";\n" +
"String k=\"a\\\"welcome\";");
while(m.find()){
System.out.println("0:"+m.group(0));
}
}
你應該告訴我們什麼樣的模式不匹配,或者更好的匹配原則是什麼。 – Tony 2014-09-06 14:07:26