In C#, we can use regular expression to do some balancing groups, like we can get
{<aa <bbb> <bbb> aa>, <<dfa>a>}
from
"xx <aa <bbb> <bbb> aa> yy<<dfa>a>"
using the regular expression
<((?<gro><)|(?<-gro>>)|[^<>])*(?(gro)(?!))>
We can get the syntax coloring with for instance RegexBuddy:
How to realize this in Mathematica?
I prefer using regular expression to do this, but Mathematica just supports some basic usage in regular expressions, and doesn't support advanced usage such as dynamic regular expression and balancing groups.
PS: Another example: how to get {[ab*[c]d], (b(x99))}
from "dd9[ab*[c]d]esiddx(45x(b(x99))"
?
StringReplace[ StringReplace[str, RegularExpression["(\\<[a-z]+\\>)+?"] :> "*"], RegularExpression["(\\<.+?\\>)"] :> "*"]
where str is the expression to match. $\endgroup$