Using regular expressions to replace text in Kile
- March 3rd, 2010
- By Mr. Nerd
- Write comment
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:
- The search expression \\verb\|([^\|]*)\| matches all \verb items, the part [^\|] simulates the non-greedy behavior.
- 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.