Sewi has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
a really simple RegEx problem is driving me crazy trying to find the most-often recurring char combination:
Why doesn't {2,} match ab?
Thanks, Sewi
a really simple RegEx problem is driving me crazy trying to find the most-often recurring char combination:
Simple, but I need to match only strings with a minimum of 2 chars:perl -le 'print $x = "abcdefgxxabcdefgzzabcdsjfhkdfab"; print $2 if $x + =~ /((\w+).*?\2.*?)+/;' abcdefgxxabcdefgzzabcdsjfhkdfab ab
Shows abcdefg but ab would be right (there is another abc behind the zz and another ab at the end).perl -le 'print $x = "abcdefgxxabcdefgzzabcdsjfhkdfab"; print $2 if $x + =~ /((\w{2,}).*?\2.*?)+/;' abcdefgxxabcdefgzzabcdsjfhkdfab abcdefg
doesn't work either, as ab would be right.perl -le 'print $x = "abcdefgxxabcdefgzzabcdsjfhkdfab"; print $2 if $x + =~ /((\w{2,}?).*?\2.*?)+/;' abcdefgxxabcdefgzzabcdsjfhkdfab cd
Why doesn't {2,} match ab?
Thanks, Sewi
Back to
Seekers of Perl Wisdom