Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Pattern Finding

by ariels (Curate)
on Sep 11, 2001 at 15:10 UTC ( [id://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)) . ')' }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found