I'm no expert on Regex. I'm trying to create a regular expression that will match the exact same number of opening and closing braces, but I'm stumped on how to do it.
An example:
nothing: important, a b { c {{{ a another {{ nothing }} }}} }
or:
one { two {{ error, forgot ending brace }}
The problem is that I don't know how many braces I'm going to get beforehand. In the first example, I need to get the text { c {{{ a another {{ nothing }} }}} }. In the second I need to get {{ error, forgot ending brace }}.
Is it even possible to create a matching rule that will do this? (I'm using Qt Regex engine).
This problem cannot be solved using regular grammar => it cannot be done by regular expression.
However - from Dirk Vollmar's comment - certain regex engines have extended functionality, e.g. the .NET one, which is capable of matching brackets using so called "balanced group definitions".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With