Hi!
Today I ran into a problem where I had to extract a JSON file passed in a YAML file within a string (don't ask me why LOL). Curly braces indicate a parameter that should be captured, so the string
P.S.: I'm using Python's
Today I ran into a problem where I had to extract a JSON file passed in a YAML file within a string (don't ask me why LOL). Curly braces indicate a parameter that should be captured, so the string
Variable {var} should have the value { {"test": {"a": 1}} }
[ should, let's say, add that value as an embedded object in a Python dictionary. While doing some research on how to come up with a regex that could match balanced curly braces, I ran into this one: ((?:[^()]|(?R))*\)
, which is supposed to match balanced parentheses. The way I see it, every time we encounter either an opening or a closing parenthesis, the recursive call will be made, and the regex will be evaluated from the beginning (it will get back to trying to match an opening parenthesis at \()
. However, if we start a recursive call for when we find a closing parenthesis as well, that recursive call will not match, because it won't start with an opening parenthesis. It doesn't make sense to me. What would make sense to me would be if we didn't have that closing parenthesis inside the [^()]
character group, but then the regex does not capture balanced parentheses only. Can someone please help me understand why?P.S.: I'm using Python's
regex
module.