I'm trying to snatch a String from a JSON text, and for some reason, I keep failing. the reason I'm not using a JSON parser is because I thought it would be easier to get it with regex since it's just one field, but I'm probably missing something little here. Here's what I'm trying to achieve:
The part of the JSON String I'm trying to get:
"text": "insert text here",
And my code:
String p1 = "\"text\": \"((?<!\\\\)\"+)\"";
Pattern pa1 = Pattern.compile(p1);
Matcher m = pa1.matcher(s);
while (m.find()) {
System.out.println(m.group());
}
My logic:
Match anything that is not '" followed by \ (\")"
If I use [^\"], it seems to work. However, there might be quotes inside the text, and the only way to make sure the text string is actually ended is finding the quote which is not proceeded by a back slash.
What am I missing here?