all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andreas Politz <politza@fh-trier.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Transposing Regular Expression
Date: Wed, 11 Nov 2009 22:45:17 +0100	[thread overview]
Message-ID: <87tyx0ka6q.fsf@fh-trier.de> (raw)
In-Reply-To: b40df352-3ed3-4f35-9304-86372ecddf9c@x5g2000prf.googlegroups.com

jrwats <jrwats@gmail.com> 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 \#) ?

You can use literal backreferences (e.g. \1) in the replacement part of
interactive uses of replace-regexp.  Combine that with expressions \,
and you could write a c-compiler in emacs-regexp/elisp.

The regular expression syntax is described in the elisp manual.

(info "(elisp)Regular Expressions")

-ap





  parent reply	other threads:[~2009-11-11 21:45 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 [this message]
2009-11-12  6:40 ` LanX
2009-11-16 12:16 ` Andreas Röhler
     [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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tyx0ka6q.fsf@fh-trier.de \
    --to=politza@fh-trier.de \
    --cc=help-gnu-emacs@gnu.org \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.