Recently, I had to replace all occurences of \verb with \texttt in a LaTeX-Document. Since my LaTeX-editor Kile supports regular expressions, this should be an easy task.

I had to work out some issues anyway: Kile does not accept the question mark modifier for non-greedy matching and I had no idea what to put in as placeholder in the replacement field.

So here’s what I finally came up with:

  1. The search expression \\verb\|([^\|]*)\| matches all \verb items, the part [^\|] simulates the non-greedy behavior.
  2. The replace expression \\texttt\{\1\} uses \1 as placeholder, this will input the part between the parentheses of the search expression.

The replacing worked really well, I had to change escape some dollar- and underscore-characters, though, since they can stand unescaped within \verb, but not within \texttt.