Hi, @zoltán-toldi, @coises, @alan-kilborn, @mark-olson and All,
My previous regex may even be shortened as :
SEARCH (?-i)^(\t+)(.+?)(\{(?:[^{}]++|(?3))*\})
REPLACE $1$2{\r\n$1}
To better understand this second search regex, we can use the free-spacing modifier (?x). Then, the search regex becomes :
(?x-i) ^ ( \t+ ) ( .+? ) ( \{ (?: [^{}]++ | (?3) )* \} )
1-----1 2-----2 3-----------------------------3
So, after finding some leading tabs \t+ and the shorter text .+?, till an opening brace \{, the regex tries to match, either :
An atomic group of characters, different from an opening and closing braces, followed with a closing brace
An other group of characters ( the group 3 ), starting with an opening brace \{, which, in turn, can be followed with :
An atomic group of characters, different from an opening and closing braces, followed with a closing brace
An other group of characters ( the group 3 ), starting with an opening brace \{, which, in turn can be followed with, either :
and so on …
Note that the third group 3 is called, from within the group itself, with the recursive back-reference (?3).
When a group x is called from inside its own group x, thanks to the (?x) syntax, this always defines a recursive regex !
Note also that the use of the recursive (?0) syntax would refer to the whole regex $0
You can control the depth of the recursion by using the {0,x} syntax, instead of the *, after the ending parenthese !
Just try, against my INPUT example, the following values :
{0,1}
{0,2}
{0,3}
{0,4}
You can verify that, with my example, the {0,4} is enough to cover all the cases. Of course, the * quantifier covers an infinite depth of recursion !
BR,
guy038