如何在Java中使用Regex在双引号之间获取字符串?
_settext(_textbox(0,_near(_span("My Name"))) ,"Brittas John");
前:我需要我的名字和布里塔斯约翰
答案 0 :(得分:3)
从括号(...)
"([^"]*)"
模式说明:
" '"'
( group and capture to \1:
[^"]* any character except: '"' (0 or more times) (Greedy)
) end of \1
" '"'
示例代码:
Pattern p = Pattern.compile("\"([^\"]*)\"");
Matcher m = p.matcher("_settext(_textbox(0,_near(_span(\"My Name\"))) ,\"Brittas John\");");
while (m.find()) {
System.out.println(m.group(1));
}
答案 1 :(得分:2)
试试这个正则表达式..
public static void main(String[] args) {
String s = "_settext(_textbox(0,_near(_span(\"My Name\"))) ,\"Brittas John\");";
Pattern p = Pattern.compile("\"(.*?)\"");
Matcher m = p.matcher(s);
while (m.find()) {
System.out.println(m.group(1));
}
}
O / P:
My Name
Brittas John