in reply to Regex backreference problem.

($_ = 'aaab') =~ m/(.)((?!\1).)/ and print "$1|$2";
Prints
a|b
Another cool way to do the same match is with the match-time pattern interpolation technique:
$_ = 'aaaabbbccddee'; while (m/(.)(.)(??{$1 eq $2})/g) { print "$1|$2\n"; }
Prints...
a|b b|c c|d d|e

Replies are listed 'Best First'.
Re: Re: Regex backreference problem.
by Anonymous Monk on Oct 10, 2003 at 06:49 UTC
    Not so cool, but my way :)
    perl -e'$_='aaabbbbccccdddd';print"$1|$2\n" while(m[(.)\1*(.)]g);'