[Tex/LaTex] how to replace [*] with \command{*} in TeXworks

texworks

I have the following lines in my document :

[Ctrl + r] : ..............
[Ctrl + u] : ..............
...
[Ctrl + m] : ..............

What I want (using TeXworks replacement wizard) is to replace all the string matching the pattern [*] by \mycommand{$1} so the lines becomes :

\mycommand{Ctrl + r} : ..............
\mycommand{Ctrl + u} : ..............
...
\mycommand{Ctrl + m} : ..............

How should I proceed ?

Best Answer

TeXworks can replace regular expressions. Use Search->Replace from the menu (or Ctrl+R), then put \[Ctrl ([^]]*)\] in the "Replace" field and \mycommand{Ctrl \1} in the "With" field, and in addition activate the "Regular expression" checkbox.

Pressing "Replace" or "Replace all" will give the desired result.