I have a string that contains a JSON object. Problem is the object is being returned like this for some reason:
string (4345) "{ "blabla" : { "bleble" : "bloblo" } ...}"
I need to extract everything between the first and last quotation basicly so that I can then decode the object.
I tried this in javascript:
var myVar = myString.match(/\".+$\"/);
But it’s not working. What’s the appropriate RegEx for my problem?
So you know that (in your example) myString has your JSONed thing? Why not do:
If there’s some other junk before or after your JSONed thing, I guess you could use the indexOf and lastIndexOf operations.
Also check out this question:
Regex to validate JSON
In response to the question in the comment:
Hope that helps. BTW if your JSON is actually coming back with the ‘, } ]”‘ at the end of it and that’s not a typo, you’d probably want to do a string.replace(/, } ]”$/, ‘}]’).