Do you know how deep the nesting goes at tis deepest? Can a new be nested in a new?
If the answers are 'yes' and 'no' there is a solution: in Robin's solution \\new\{([^}]*)\}
replace the [^}]*
with, for example, [^{}]*({[^{}]*})?[^{}]*
which is "any number of characters that are not {}
" followed by maybe an opening bracket, a number of non-brackets, and a closing one, followed by again zero or more not-brackets. This will match nesting up to two. For every extra level of nesting, you need to replace the middle [^{}]*
with another [^{}]*({[^{}]*})?[^{}]*
leading to fun like \\new\{[^{}]*({[^{}]*({[^{}]*({[^{}]*})?[^{}]*})?[^{}]*})?[^{}]*\}
(4 levels).