help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Query replace regex with 2 alternatives


From: Barry Margolin
Subject: Re: Query replace regex with 2 alternatives
Date: Fri, 07 Dec 2012 13:59:06 -0500
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article <icd2ylg5zz.fsf@home.home>, Dan Espen <despen@verizon.net> 
wrote:

> Could use some help on query/replace/regex.
> 
> I have an html file full of &lt; and &gt;.
> I want to replace only some of the pairs with "[" and "]".
> 
> I figured out the match string:
> 
> "\\(&lt;\\|&gt;\\)
> 
> (typed as)
> 
> "\(&lt;\|&gt;\)
> 
> but when it comes to the replacement, I'm not clear on how to say,
> first match gets [ and second match gets ].

Do two separate query-replaces, one to replace &lt; with [, the other to 
replace &gt; with ].

> I believe emacs can do it but I don't see it documented.
> I see references to \1 \2 but not in the replace string.

I think what you're talking about is:

&lt;\(.*?\)&gt;
Relace with:
[\1]

Or maybe this is what you mean:

&lt;\|&gt;
Replace with:
\,(if (string-equal \& "&lt;" "[" "]"))

This latter option is only available in interactive mode, not when 
calling query-replace-regexp from Elisp.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


reply via email to

[Prev in Thread] Current Thread [Next in Thread]