From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: harven Newsgroups: gmane.emacs.help Subject: Re: Transposing Regular Expression Date: Wed, 11 Nov 2009 21:51:42 +0100 Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1257975698 13709 80.91.229.12 (11 Nov 2009 21:41:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 11 Nov 2009 21:41:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 11 22:41:31 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 1N8KwT-0004tA-1b for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Nov 2009 22:41:29 +0100 Original-Received: from localhost ([127.0.0.1]:42035 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N8KwS-00016Z-IY for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Nov 2009 16:41:28 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!goblin3!goblin.stu.neva.ru!de-l.enfer-du-nord.net!usenet-fr.net!proxad.net!feeder1-2.proxad.net!cleanfeed1-b.proxad.net!nnrp8-2.free.fr!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (darwin) Cancel-Lock: sha1:pTvnCI6ATP88QdPmy/3fQQiwgbI= Original-Lines: 32 Original-NNTP-Posting-Date: 11 Nov 2009 21:51:43 MET Original-NNTP-Posting-Host: 78.233.232.132 Original-X-Trace: 1257972703 news-4.free.fr 31204 78.233.232.132:58068 Original-X-Complaints-To: abuse@proxad.net Original-Xref: news.stanford.edu gnu.emacs.help:174602 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:69677 Archived-At: jrwats writes: > Perl provides the transpose operator: > =~ tr/abc/xyz/ not really a regular expression, but exchanges 'x' for > 'a', 'y' for 'b', and 'z' for 'c' in the source string. > > My question is how to accomplish this in emacs. When only needing to > tranpose 2 characters that need to replace each other, (the equivalent > perl expression woud be =~ tr/ab/ba/ as an example, I could simply > regexp replace 'a' with a unique letter or symbol, maybe '$' for > instance, then replace all b's with a's and all $'s with b's. This > obviously becomes unweildy after we start transposing more than 2 > characters. My question is, now that emacs provides fancy regexp > replace clauses: \# for the number match, and arbitrary lisp > expressions \,(some-lisp), etc, is there a way to accomplish this in > one fell swoop via a very crazy regular expression find-replace? Also > is there a list of meaningful regular expression search escape > characters somewhere (like \#) ? The emacs manual gives the following snippet for swapping two values. M-x replace-regexp \(x\)\|y \,(if \1 "y" "x") Note that you can swap two words by the same method. This is not exactly what you are looking for though. There are many functions that have been devised to swap values according to an alist, e.g. for converting accents from iso8859-1 to html. These can be easily adapted to get a command emulating tr. Cheers