Given the following string:
"<head></head><body>{"filesize":55312,"success":false,"msg":"incorrect-captcha-sol"}<div firebugversion="1.5.4" style="display: none;" id="_firebugConsole"></div></body>"
I need to extract the JSON string as follows:
{"filesize":55312,"success":false,"msg":"incorrect-captcha-sol"}
How should I do this?
Thank you
Given the following string:
"<head></head><body>{"filesize":55312,"success":false,"msg":"incorrect-captcha-sol"}<div firebugversion="1.5.4" style="display: none;" id="_firebugConsole"></div></body>"
I need to extract the JSON string as follows:
{"filesize":55312,"success":false,"msg":"incorrect-captcha-sol"}
How should I do this?
Thank you
Share Improve this question edited Aug 14, 2010 at 1:39 Delan Azabani 81.6k30 gold badges172 silver badges212 bronze badges asked Aug 14, 2010 at 1:38 q0987q0987 36.1k74 gold badges258 silver badges407 bronze badges3 Answers
Reset to default 3 json = str.match(/(\{[^}]+\})/)[1];
json = str.match(/([^<]+)/)[1];
A regular expression like
({[^}]+})
would work.
Try it out using RegExr.