in reply to Re: How to do it in one line?
in thread How to do it in one line?

I don't suppose that someone would consider explaining how this works for me?

I spent a couple of hours on trying to understand this in conjunction with perlman:perlre and I am frankly lost.

Replies are listed 'Best First'.
Re: How to do it in one line?
by Abigail-II (Bishop) on Jul 08, 2002 at 16:28 UTC
    s/(\G # Either were we finished the previous time # (or at the beginning the first time). | # Or (.)(?!\2)) # A character ($2) not followed by itself ( # Capture ($3) (.)\4(?!\4) # A character ($4) followed exactly once by + itself. ) # End capture ($3) /$2($3)/xg # Replace with $2 (what preceeded) followed + by # "($3)" (the duplicate).
    It boils down to that if you have exactly two occurances of a character, something else should preceed those chararcters, or they should be at the beginning of the string (or were we left off the previous time).

    Abigail