in reply to How to do it in one line?

seems like homejob, because it's useless but tuitfull. Anyway (on Win32 shell):
perl -wne "s/(.)\1+(?!\1)/length($&)>2?qq[$&]:qq[($1$1)]/ge;print" fil +e.txt
on Unix just
perl -wne 's/(.)\1+(?!\1)/length($&)>2?qq[$&]:qq[($1$1)]/ge;print' fil +e.txt
Got same result on your input!

Courage, the Cowardly Dog.

Replies are listed 'Best First'.
Re2: How to do it in one line?
by blakem (Monsignor) on Jul 04, 2002 at 06:49 UTC
    Same basic idea, but I shaved a few chars off of it....
    # 1 2 3 4 #2345678901234567890123456789012345678901234 perl -pe's/(.)\1(\1*)(?!\1)/$2?$&:"($&)"/ge' file.txt

    -Blake

      Thanks a lot, although it is not a homejob ;-) Question is if itīs possible using exclusively regex (no ternary operator).

      Explore the unknown,
      know the known.

      -r