I have a string "Hello" hello (including the quotes) and i just want to get the Hello that has the quotes but without the quotes
i tried using regular expression but it never finds the quotes im guessing
String s = new String("string");
Pattern p = Pattern.compile("\"([^\"])\"");
Matcher m = p.matcher(n);
while (m.find()) {
s = m.group(1);
}
the while loop never gets executed, suggestions?
— Moved the star inside the parenthesis for proper grouping —
Tested successfully with the code
which produced the expected output
— Original post follows —
You don’t match anything because your regex is written to only match quoted one character strings.
is closer to what you need. Note the star, it means zero or more of the preceeding expression. In this case the preceeding expression is “anything that lacks a double quote”.