Saturday, 15 September 2012

How do I match a JSON object with a unique ID using regex -



How do I match a JSON object with a unique ID using regex -

i have next json object:

{ "fieldid": "id1", "isvisibleindetails": true, "isvisibleingrid": true, "columnwidth": 142, }, { "fieldid": "id2", "isvisibleindetails": true, "isvisibleingrid": true, "columnwidth": 100, }, { "fieldid": "id3", "isvisibleindetails": true, "isvisibleingrid": true, "columnwidth": 159, }

i want match following:

{ "fieldid": "id2", "isvisibleindetails": true, "isvisibleingrid": true, "columnwidth": 100, },

i've tried using regex (\{.*)id2(.*?)\}, match returns as:

{ "fieldid": "id1", "isvisibleindetails": true, "isvisibleingrid": true, "columnwidth": 142, }, { "fieldid": "id2", "isvisibleindetails": true, "isvisibleingrid": true, "columnwidth": 100, },

can please right regex?

use regular look \{[^{]*id2[^}]*?\}

regex json match

No comments:

Post a Comment