help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Transposing Regular Expression


From: jrwats
Subject: Transposing Regular Expression
Date: Wed, 11 Nov 2009 09:25:26 -0800 (PST)
User-agent: G2/1.0

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 \#) ?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]