开发者

Javascript Regular Expression to parse JSON

开发者 https://www.devze.com 2022-12-15 20:23 出处:网络
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. 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. Regular expression to parse JSON

Again I am not looking to get JSON.parse and get the json object, I need开发者_Go百科 to find the regex for the pattern.

Thanks


/\[\[.*?\]\]/g

G - Global (find more than once)


for complex objects, you can further try this -

\{.*\:\{.*\:.*\}\}

{"ABC":{"Prop1":false,"Prop2":"abc","Prop3":false}}

Tested it @ http://www.regextester.com/


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|.)*?\]\]/);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号