From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: Transposing Regular Expression Date: Mon, 16 Nov 2009 13:16:35 +0100 Message-ID: <4B0142A3.5000707@easy-emacs.de> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1258373886 16252 80.91.229.12 (16 Nov 2009 12:18:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Nov 2009 12:18:06 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: jrwats Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 16 13:17:59 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 1NA0Wr-0002mi-LS for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Nov 2009 13:17:58 +0100 Original-Received: from localhost ([127.0.0.1]:59529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NA0Wq-0004Y6-Tu for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Nov 2009 07:17:56 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NA0WS-0004Xt-Ph for help-gnu-emacs@gnu.org; Mon, 16 Nov 2009 07:17:32 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NA0WL-0004VV-Oz for help-gnu-emacs@gnu.org; Mon, 16 Nov 2009 07:17:31 -0500 Original-Received: from [199.232.76.173] (port=42748 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NA0WL-0004VS-MM for help-gnu-emacs@gnu.org; Mon, 16 Nov 2009 07:17:25 -0500 Original-Received: from moutng.kundenserver.de ([212.227.17.8]:60220) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NA0WL-0006Vf-4P for help-gnu-emacs@gnu.org; Mon, 16 Nov 2009 07:17:25 -0500 Original-Received: from [192.168.178.27] (p54BEB8A4.dip0.t-ipconnect.de [84.190.184.164]) by mrelayeu.kundenserver.de (node=mrbap0) with ESMTP (Nemesis) id 0LkSV9-1NlpBB2Sfz-00buJU; Mon, 16 Nov 2009 13:17:23 +0100 User-Agent: Thunderbird 2.0.0.19 (X11/20081227) In-Reply-To: X-Provags-ID: V01U2FsdGVkX19NmRxTlvMySTtIr7St4Qm+XjSy2xi2kegXM5L L+SGdSh7td86qF6+eU2mjjfIel/nJx/Urz+Rt/xTdkx4r9Z4wm xENhByTMmyTTuU+hHp4DzEYT5UlK0MjFxVkehbtSew= X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. 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:69776 Archived-At: jrwats wrote: > 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 \#) ? > 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 (search-forward "abc" nil t 1) (replace-match "xyz")) Andreas -- https://code.launchpad.net/s-x-emacs-werkstatt/ http://bazaar.launchpad.net/~a-roehler/python-mode/python-mode.el/