Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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

by tye (Sage)
on Jun 18, 2013 at 20:13 UTC ( #1039649=note: print w/replies, xml ) Need Help??

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

Note that, based on that definition, if the first and last characters are the same, then the answer is "the string minus the last character". Which leads to:


Which leads to a full solution of:


which might be horribly inefficient (at least for some cases) or might not; I haven't considered it.

- tye        

Replies are listed 'Best First'.
Re^4: Finding repeat sequences. (only regex)
by BrowserUk (Pope) on Jun 18, 2013 at 20:21 UTC

    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.

      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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039649]
Discipulus what's SioB?
[Eily]: Saints in our Book
[Discipulus]: ..mmhh: no warnings; does not affect carp.. how to suppress carp's output in tests?
[margeas]: What is the average response time of gods ?
[1nickt]: @CARP_NOT
[Corion]: margeas: I'll look at renaming you ;)
[markong]: ahah thanks Corion :)
[Eily]: Discipulus usually it's while testing that you want the full logs :)
[Eily]: anyway, maybe you can ignore STDERR ? (I'm not sure about @CARP_NOT, it looks like it only changes the place the error comes from)

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2018-01-22 11:20 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (233 votes). Check out past polls.