<分区>
要匹配的示例源代码是
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));
}
}