Regex To Get All Contents Within Curly Brackets


Let us say your string contains this data

1
{"1":"one", "2":"two"},{"3":"three", "4":"four"},{"5":"five", "6":"six"}

While regex can slow down performance, I decided to use it for this situation because I can do it using only a regex pattern. This regex will get all instances of a substring between two curly brackets { and }. In the example above, the result should be 3 entries since there are 3 sets of curly brackets. Please see the regular expression below.

1
\\{[^}]*\\}

Found this post useful? Buy me a cup of coffee or subscribe to my RSS feeds and Google Friend Connect

Related Posts with Thumbnails

Leave a Reply

Spam protection by WP Captcha-Free