From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: Query replace regex with 2 alternatives Date: Fri, 07 Dec 2012 13:59:06 -0500 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1354906819 22413 80.91.229.3 (7 Dec 2012 19:00:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 7 Dec 2012 19:00:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 07 20:00:33 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Th39w-0006Gc-UI for geh-help-gnu-emacs@m.gmane.org; Fri, 07 Dec 2012 20:00:29 +0100 Original-Received: from localhost ([::1]:38289 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Th39j-0004Mh-5f for geh-help-gnu-emacs@m.gmane.org; Fri, 07 Dec 2012 14:00:15 -0500 Original-Path: usenet.stanford.edu!news.glorb.com!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 44 Injection-Info: barmar.motzarella.org; posting-host="78fb7125a45724f15e21604c94a7d968"; logging-data="6078"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9V8HV3hgmGAlLi95fY8JE" User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Cancel-Lock: sha1:Wjfl6yw0fJKUfIDEjUxAtgmlOHs= Original-Xref: usenet.stanford.edu gnu.emacs.help:195752 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:88074 Archived-At: In article , Dan Espen 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 ***