Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: Finding repeat sequences. (only regex)

by BrowserUk (Pope)
on Jun 18, 2013 at 20:21 UTC ( #1039652=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Finding repeat sequences. (only regex)
in thread Finding repeat sequences.

Nice reversal of the logic and closer:

$s = 'aaaabaaaabaaaaabaaaab';; $s =~ /^((.*?).*?)\2*\1$/ and print "$2/$1";; a/aaaabaaaab

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re^4: Finding repeat sequences. (only regex)
Download Code
Replies are listed 'Best First'.
Re^5: Finding repeat sequences. (only regex!)
by tye (Cardinal) on Jun 18, 2013 at 21:17 UTC

    I think I had \1 and \2 backward. Then you just have to disallow the trivial solution:

    $s = 'aaaabaaaabaaaaabaaaab'; $s =~ /^((.*?).*?)(?=.)\1*\2$/ and print "$2/$1";

    (Update: Dropped the unneeded () around \1 that I had introduced while debugging. You probably also need to change .*? to .* so you get the longest solution not the shortest.)

    - tye        

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2015-07-07 18:38 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 (93 votes), past polls