I'm trying to match an object inside some stringified json (because of some unfortunate server-specific PHP limitations).
My attempt: /\{\s*"first":"first_entry_match"[.\s]*?\}/
This should match any object inside the json whose first parameter is "first" with a corresponding value of "first_entry_match". After playing around, I've found that the .
isn't working -- using [\s\w":,]
goes very far, but I may end up dealing with some unicode and want to simply match everything until I get to the first }
I see.
JSFiddle (I'm using PHP, but this illustrates the problem. Note that in my case, I do have newline characters in the json string)
To match all the chars upto the first }
symbol, use a negated character class with the symbol }
, ie. [^}]*
/\{\s*"first":"first_entry_match"[^}]*\}/
You have put the dot in the brackets. The dot represents every character when it is outside the bracket, inside, it simply represents the dot character.
Just use this:
/\{\s*"first":"first_entry_match".*?\}/
.*?
ensures there will be no }
in the selection. (non-greedy)