emacs Regular Expressions (regexp) Examples

||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}
blog_tags: 

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <img> <br> <p> <span>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Use [collapse] and [/collapse] to create collapsible text blocks. [collapse collapsed] or [collapsed] will start with the block closed.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Code snippets in <code>...</code> or <source>...</source> automatically will be pretty printed.
  • Use [collapse] and [/collapse] to create collapsible text blocks. [collapse collapsed] or [collapsed] will start with the block closed.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Target Image