Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?)



On Dec 28, 1:52 pm, Ted Zlatanov <t...@xxxxxxxxxxxx> wrote:

Actually, I've often run into the need for parallel edits like this,
where you want to s/A/B/ and s/B/C but you don't want A to become C.
With complex operations or operations you don't know in advance, proper
ordering becomes impossible.  I usually handle it with function calls:
s/[ABC]/replacement(\1)/e or something like that.  Is there a better
approach anyone can recommend?


What does the above do? Shouldn't that be:
s/[ABC]/replacement( $1 )/e;

?

And could you please expound on "With complex operations or operations
you don't know in advance..."?
I don't see how you could avoid doing an inadvertent A->C if you did
multiple s/// out of order, unless you provided enough context for the
regex to work correctly.
.



Relevant Pages