So you want to combine
[noncurlies [block noncurlies [...]]] "}"
where a block is
"{" [noncurlies [block noncurlies [...]]] "}"
Like a grammar:
start : text "}" text : noncurly* ( block noncurly* )* block : "{" text "}" noncurly : /[^{}]/
As a regular expression (5.10 +):
/ ^ ( ( [^{}]* (?: \{ (?-1) \} [^{}]* )* ) \} ) /x
As a regular expression (5.10 +):
/ ^ ( (?&TEXT) \} ) (?(DEFINE) (?<TEXT> [^{}]* (?: (?&BLOCK) [^{}]* )* ) (?<BLOCK> \{ (?&TEXT) \} ) ) /x
source share