[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 < and >.
> I want to replace only some of the pairs with "[" and "]".
>
> I figured out the match string:
>
> "\\(<\\|>\\)
>
> (typed as)
>
> "\(<\|>\)
>
> 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 < with [, the other to
replace > 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:
<\(.*?\)>
Relace with:
[\1]
Or maybe this is what you mean:
<\|>
Replace with:
\,(if (string-equal \& "<" "[" "]"))
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 ***