From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: jrwats Newsgroups: gmane.emacs.help Subject: Re: Transposing Regular Expression Date: Mon, 16 Nov 2009 08:28:08 -0800 (PST) Organization: http://groups.google.com Message-ID: <0c6047e0-9b7c-482d-a083-3b24c9dd0a00@k13g2000prh.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1258389660 10128 80.91.229.12 (16 Nov 2009 16:41:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Nov 2009 16:41:00 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 16 17:40:53 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NA4dF-0004O7-Jw for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Nov 2009 17:40:50 +0100 Original-Received: from localhost ([127.0.0.1]:46427 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NA4dF-0000tI-4H for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Nov 2009 11:40:49 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!postnews.google.com!k13g2000prh.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 24 Original-NNTP-Posting-Host: 71.227.232.135 Original-X-Trace: posting.google.com 1258388888 9016 127.0.0.1 (16 Nov 2009 16:28:08 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Mon, 16 Nov 2009 16:28:08 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k13g2000prh.googlegroups.com; posting-host=71.227.232.135; posting-account=bFjqRgoAAAA1g2eFs8HouoaeO5EHoWR2 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.5) Gecko/20091109 Ubuntu/9.10 (karmic) Firefox/3.5.5,gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:174706 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:69781 Archived-At: > IIUC you are going to change strings. > > That's a simple task then with no need to employ > \# for the number match ore other advanced features. > > Interactivly just call > > M-x query-replace - putting in your strings at the prompt. > > From a program use for example > > (while > =A0 (search-forward "abc" nil t 1) > =A0 (replace-match "xyz")) That's not exactly what I'm looking for as I really need 2 words/ characters to be swapped. For instance, swapping "true" and "false" in a region. Replacing all the "true"s with "false"s will yield a 1/2 correct answer but there's no way to replace the old false's anymore. LanX's solution appears to do the correct thing regarding an actual Perl-style transpose, and seeems like it could easily be altered to work on a region. The quickest solution for the simple 2-way swap was definitely the back reference (example provided by harven).