in reply to Pattern Finding
(In perl -de 17:)
DB<6> $x = 'helloworldhellohellohihellohiworldhi' DB<7> print "$1\n" while $x =~ /(\w+)(?=.*\1.*\1)/g hello o l hello h l l o hi h l
The single letters appear, of course, since they're repeated more than once. We can fix that by requiring \1 to be at least 2 characters long...
Of course it still finds `world', which appears 4 times.DB<8> print "$1\n" while $x =~ /(\w{2,})(?=.*\1.*\1)/g hello hello hi
To autogenerate the regexp:
sub repeat_finder_re { my $n = shift; '(\w{2,})(?=' . ('.*\\1'x($n-1)) . ')' }
|
---|
In Section
Seekers of Perl Wisdom