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.

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.

11 Years
Discussion Span
Last Post by Phaelax

So how can I tell it to ignore escape characters?

if this is the text:

Then everything should match except the plus sign.
I've tried stating for no escape character before the quotes, but I may not have done this properly.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.