How can i get Strings between double quotes using Regex in Java?
_settext(_textbox(0,_near(_span("My Name"))) ,"Brittas John");
ex: I need My Name and Brittas John
Get the matched group from index 1 that is captured by enclosing inside the parenthesis (...)
"([^"]*)"
Pattern explanation:
" '"'
( group and capture to \1:
[^"]* any character except: '"' (0 or more times) (Greedy)
) end of \1
" '"'
sample code:
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));
}
Try this regex..
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
".