I was trying to re-structure my latex document but I failed to do it in a single query regex. My goal was to the following transformation:

\item[root] → \item \textbf{root}

I tied grouping the content withing the brackets and then using in the replacement but it did not work.

This was my attempt:

Alt-S-% \\[\(.*\)] RET \\textbf{\1} RET

I tried playing with the regexp-builder but it seems to have a slightly different syntax than then replace-regexp command.

1 Answer 1


\ escapes [ and itself, so \\ matches a backslash and \[ matches an open bracket. So \\[\(.*\)] matches a backslash followed by a dot, a parenthesis or a star.

Instead, you presumably wanted to use \[\(.*\)] which should give you the right result. Rather than re-builder, you can also use:

C-s M-r \[\(.*\)] M-% \\textbf{\1} RET

which also gives you interactive feedback about your regexp.

  • Thanks for the tip of C-s and then M-% it is better for this task.
    – Hydrocat
    May 13, 2019 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.