From: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
To: jrwats <jrwats@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Transposing Regular Expression
Date: Mon, 16 Nov 2009 13:16:35 +0100 [thread overview]
Message-ID: <4B0142A3.5000707@easy-emacs.de> (raw)
In-Reply-To: <b40df352-3ed3-4f35-9304-86372ecddf9c@x5g2000prf.googlegroups.com>
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/
next prev parent reply other threads:[~2009-11-16 12:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-11 17:25 Transposing Regular Expression jrwats
2009-11-11 20:51 ` harven
2009-11-11 21:45 ` Andreas Politz
2009-11-12 6:40 ` LanX
2009-11-16 12:16 ` Andreas Röhler [this message]
[not found] ` <mailman.10804.1258373854.2239.help-gnu-emacs@gnu.org>
2009-11-16 16:28 ` jrwats
2009-11-17 2:13 ` LanX
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B0142A3.5000707@easy-emacs.de \
--to=andreas.roehler@easy-emacs.de \
--cc=help-gnu-emacs@gnu.org \
--cc=jrwats@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).