in reply to Is there an elegant way of resetting the match position?

Try

[0] Perl> $s = "Input String: aaAabBAAa";; [0] Perl> $n=1; print "'$1'" while $s =~ m[(?=((.)\2{$n}))]ig;; 'aa' 'aA' 'Aa' 'bB' 'AA' 'Aa' [0] Perl> $n=2; print "'$1'" while $s =~ m[(?=((.)\2{$n}))]ig;; 'aaA' 'aAa' 'AAa'

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP PCW It is as I've been saying!(Audio until 20090817)

Replies are listed 'Best First'.
Re^2: Is there an elegant way of resetting the match position?
by LanX (Saint) on Oct 22, 2009 at 21:57 UTC
    thanx ...
    DB<1> $s = "aaAabBAAa";; DB<2> $n=1; print "'$1'",pos($s) while $s =~ m[(?=((.)\2{$n}))]ig 'aa'0'aA'1'Aa'2'bB'4'AA'6'Aa'7 DB<3> $n=1; print "'$1$2'",pos($s) while $s =~ m[(.)(?=(\1{$n}))]ig 'aa'1'aA'2'Aa'3'bB'5'AA'7'Aa'8 DB<4> $n=2; print "'$1$2'",pos($s) while $s =~ m[(.)(?=(\1{$n}))]ig 'aaA'1'aAa'2'AAa'7

    ... fascinating to see capture work within a lookahead and to investigate how pos() behaves...

    Cheers Rolf