I'm trying to find all quoted strings in a given text so that I can apply proper highlighting. I've tried various regex but can't seem to get the results I want.
String line = "a big \"yellow\" dog! And a \"purple\" bird!";
String[] tokens = line.split("\".+\"");
That cuts out everything from 'yellow' to 'purple'. Is there a way to set the regex so that after the first match is found it cant be part of subsequent matches?
Given the string above, what I need is to extract "yellow" and "purple" only, including their quotations.
[edit]
Ok, just about got it.
Pattern p = Pattern.compile("\".+?\"");
String test = "testing some stuff"+"some more stuff";
Works as expected there. But if the string contains escaped quotes:
\"
then it throws it off.