From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Espen Newsgroups: gmane.emacs.help Subject: Re: Query replace regex with 2 alternatives Date: Fri, 07 Dec 2012 15:06:48 -0500 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1354911010 26463 80.91.229.3 (7 Dec 2012 20:10:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 7 Dec 2012 20:10:10 +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 21:10:24 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 1Th4Fc-0007Kg-3e for geh-help-gnu-emacs@m.gmane.org; Fri, 07 Dec 2012 21:10:24 +0100 Original-Received: from localhost ([::1]:33191 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Th4FP-00087b-S7 for geh-help-gnu-emacs@m.gmane.org; Fri, 07 Dec 2012 15:10:11 -0500 Original-Path: usenet.stanford.edu!news.glorb.com!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 62 Injection-Info: mx04.eternal-september.org; posting-host="960b39603e44c0554faedf0065e3beaf"; logging-data="7359"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/EdCA3RVrpvsLf9nOlOgLxUokNCu3niQ=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) Cancel-Lock: sha1:AO++rRzp/tTYM/V7esSqlYSLMR8= sha1:rDQK6AuifkQr38O4dqJvPv1BxfU= Original-Xref: usenet.stanford.edu gnu.emacs.help:195753 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:88076 Archived-At: Barry Margolin writes: > 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] Thanks Barry, that worked for what I wanted and is perhaps better. > Or maybe this is what you mean: > > <\|> > Replace with: > \,(if (string-equal \& "<" "[" "]")) This is what I was asking for. I pasted both values into emacs and the latter part gave me an error, (wrong-number-of-arguments if 1). The same error I get if I try to evaluate the expression. Not important now, I got the idea. I don't see "\," here: http://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Backslash.html#Regexp-Backslash http://tinyurl.com/aqod6fv okay, I do see it here: http://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Replace.html#Regexp-Replace It would have helped if I looked at the current documentation... Thanks again. -- Dan Espen