Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Pattern Finding

by runrig (Abbot)
on Sep 11, 2001 at 03:08 UTC ( #111624=note: print w/ replies, xml ) Need Help??


in reply to Pattern Finding

Untested, and not very thought out:

$_ = "hellohiworldhellohiworldhellohiworldhellohiworld"; if (/^((.+?)\2+)$/) { print "[$1][$2]\n"; }
Update: Hmm, this does not work, and I'm not sure why (regex bug? or bad code?) :-(

Ok, got the above code to work at least the way I was expecting, but still probably not what you want.

<update>Though here's something that seems to do what you want:

use warnings; use strict; $_ = "helloworldhellohellohihellohiworld"; my %pttrns; PTTRN: { if (/\G(.{2,})(?=.*?\1)/g) { $pttrns{$1}++; SKIP: { my $again; for my $pat (keys %pttrns) { if (substr($_, pos, length $pat) eq $pat) { pos() += length($pat); redo SKIP; } } } redo PTTRN; } } print "[$_]\n" for keys %pttrns; ~/tmp >./tst [world] [hello] [hi]


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://111624]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2014-08-21 16:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (136 votes), past polls