[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Transposing Regular Expression
From: |
jrwats |
Subject: |
Re: Transposing Regular Expression |
Date: |
Mon, 16 Nov 2009 08:28:08 -0800 (PST) |
User-agent: |
G2/1.0 |
> 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"))
That's not exactly what I'm looking for as I really need 2 words/
characters to be swapped. For instance, swapping "true" and "false"
in a region. Replacing all the "true"s with "false"s will yield a 1/2
correct answer but there's no way to replace the old false's anymore.
LanX's solution appears to do the correct thing regarding an actual
Perl-style transpose, and seeems like it could easily be altered to
work on a region. The quickest solution for the simple 2-way swap was
definitely the back reference (example provided by harven).