# How to Use Regex to Replace All Occurrences of "\ctft{*}" into "\application{\ctftop}{*}"


• That's a question about the editor, rather than TeX. Feb 14 at 21:23
• you can not mach arbitrary nested braces with a regex (that's essentially what the "regular" in "regular expression" means) but why do you ned a regex, don't you just want to change \ctft{ to \application{\cftop}{ ? Feb 14 at 21:27
• your \application macro seems wrong, \application{\sin}{x} would produce {\sin}{x}not \sin {x} so would lose the operator spacing for \sin Feb 14 at 21:31
• @DavidCarlisle - If we're talking about balanced nested braces, you can try putting \ctft{\delta_{a}} in a .tex file, do M-x re-builder in your favorite editor and yank this snippet for the regexp string: \\\\ctft{\$$[^}{]*\\({[^}{]*}[^}{]*\$$*[^}]*\\)}. Things get complicated once you have escaped braces. Feb 15 at 11:39
• @ArashEsbati you can match braces to any fixed depth, that one if I read it right matches {} containing possible {} groups that don't contain braces. but regex can not count (some systems provide non-regular extensions that can match braces) so you can not match {{{{a}b}c}} with the one you show. Feb 15 at 12:22

You do not need a regex here, just replace \ctft{ by \application{\cftop}{