Let's take your original regular expression. I just now see one flaw: "\"*\"" means zero or more occurrences of " followed by a single ". That's because in regular expressions * is a meta character that applies to the previous entity, in this case the ". It doesn't work like command line wild
cards where * means "any character any number of times". A quick (and incorrect) fix: "\".*\"". That dot makes the * bind to that, so the regular expression becomes a single " followed by any character any number of times followed by a single ". That looks more like it. So we
test it:
Output: "A")),list(groups("B")),list(groups("C"
Not quite what we want, and the reason is simple: .* is
greedy. It takes everything between the first " and the
last ". What we want is to take everything between each " and the next ".
There are two ways:
1) make the matching not greedy but reluctant. We do this by appending a simple ? behind the *; see also the Javadoc I pointed you to. The regex becomes "\".*?\".
2) do not capture everything but only everything that's not a ". We can use a negating character class for that: [^"]. The regex becomes "\"[^\"]*\"".
Both now result in this output:
"A"
"B"
"C"
Now all you need to do is use substring to get the values. Another option is use a matching group, by using ( and ). You will then get a group 1 inside the matcher. Group 0 (the entire match, which is what group() returns; group() and group(0) are equivalent) is no longer relevant:
Output:
A
B
C
Note that it's important to use a loop for find(), and not a single if. That's because you can have multiple matches, and with if you only check the first one. The loop will let you check them all.