So, I’m looking to extract words (or phrases) within quotation marks (“) out of a string.
For example suppose the main string is:
The quick brown fox "jumped over" the "lazy" dog
I’d like to be able to extract out and store in variables the words/phrases in quotes, i.e.
jumped over
lazy
should be stored in variables. The input strings will only double quotes when quoting (no single quotes).
I tried the following (rough) code for this:
Pattern p = Pattern.compile("\\s\"(.*?)\"\\s");
Matcher m = p.matcher(<String>);
Variable.add(m.group(1));
It’s throwing an IllegalStateException no matter what I input in. I have a feeling my regex is not working properly.
Any help is appreciated.
Your code lacks some
if( m.matches())orm.find()which do the job…This code:
outputs: