Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^5: substrings that consist of repeating characters

by choroba (Archbishop)
on Sep 29, 2020 at 21:20 UTC ( #11122351=note: print w/replies, xml ) Need Help??

in reply to Re^4: substrings that consist of repeating characters
in thread substrings that consist of repeating characters

I tried turning
use re 'debug';
on and comparing the output with
which seems to work, but I don't understand the output enough to be able to explain why the behaviour is different.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^6: substrings that consist of repeating characters
by salva (Canon) on Sep 30, 2020 at 07:32 UTC
    Aja, that has allowed me to see the problem!

    The (*SKIP) inside the repetition always matches, but once the end of the same-char sequence is reached the \2 fails, so it causes the repetition to backtrack, but it can't because of the (*SKIP), so all the repetition fails!

    Moving the (*SKIP) after the \2 fixes the issue:

    my $string = "ATTTAGTTCTTAAGGCTGACATCGGTTTACGTCAGCGTTACCCCCCAAGTTTTTTT +TTTTTTTTTTTATTGGGGACTTT"; my $len = 0; my $best = ""; while ($string =~ /((.)(\2(*SKIP)){$len,})/g) { $len = length $1; $best = $1 } print "best: $best\n"

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2022-05-27 07:22 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (94 votes). Check out past polls.