Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Pattern Finding

by ariels (Curate)
on Sep 11, 2001 at 15:10 UTC ( #111709=note: print w/ replies, xml ) Need Help??


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...

DB<8> print "$1\n" while $x =~ /(\w{2,})(?=.*\1.*\1)/g hello hello hi
Of course it still finds `world', which appears 4 times.

To autogenerate the regexp:

sub repeat_finder_re { my $n = shift; '(\w{2,})(?=' . ('.*\\1'x($n-1)) . ')' }


Comment on Re: Pattern Finding
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://111709]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (17)
As of 2015-07-30 15:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (272 votes), past polls