nutalk nutalk - 3 months ago 14
Javascript Question

Javascript Regular Expression to parse JSON

I asked a question about regular expression in PHP (which got answered), I need help with same regular expression in javascript, here is the link to previous question. http://stackoverflow.com/questions/2015320/need-help-with-writing-regular-expression

Again I am not looking to get JSON.parse and get the json object, I need to find the regex for the pattern.

Thanks

Answer

Try something like:

var matches = text.match(/\[\[.*?\]\]/);

matches[0] will be the matched string.

Since the DOTALL PCRE option isn't supported in Javascript, you'd have to use a regular expression like that:

var matches = text.match(/\[\[(?:\s|.)*?\]\]/);