s/./=&&/g s/$/;ABCDEFGHIJ/ :1 s/\(.\)\1\(\(=.\1\)*=.\)\(.\)\(.*;.*\1.*\4\)/\1\4\2\1\5/ t1 : s/\(.\)\(=.\(.\)\(=.\3\)*=\3\)\3/\3\2\1/ t s/\(=.\)\(.\)\1\(.\)\(.*;.*\3.*\2\)/\1\3\1\2\4/ t s/=.\|;.*//g
Note that non-ascii characters in the above source code will be escaped (such as \x9f).