emacs Regular Expressions (regexp) Examples
Posted by rolf on Tuesday, 4 August 2015
||Symbols Text a^2|| -> \norm{Symbols Text a^2}
in Latex change I defined my own norm environment, using the \usepackage{amsmath} environment, by
\newcommand{\norm}[1]{\left\Vert#1\right\Vert}
Now I wanted to replace every pair || . || with \norm{.}, e.g.
||a^2 - b^2||^2
to
\norm{a^2 - b^2}^2
REGEXP
M-x query-replace-regexp
||\(.*?\)||
with
\\norm{\1}
The .* matches everything in a greedy way, that means a expression like
|| test || + || test2||
would be matched and replaced to
\norm{test || + ||test2}
What we want is a non-greedy regexp, hence the .*?, this replaces above to
\norm{ test} + \norm{test2}
Add new comment