Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: substrings that consist of repeating characters

by AnomalousMonk (Archbishop)
on Sep 29, 2020 at 17:37 UTC ( [id://11122344]=note: print w/replies, xml ) Need Help??


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

Does that work?

Win8 Strawberry 5.30.3.1 (64) Tue 09/29/2020 13:32:10 C:\@Work\Perl\monks >perl use strict; use warnings; my $string = 'AABBBBCCC'; my $len = 0; my $best = ""; while ($string =~ /((.)(?:(*SKIP)\2){$len,})/g) { $len = length $1; $best = $1 } print "best: '$best' \n" ^Z best: ''


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^4: substrings that consist of repeating characters
by salva (Canon) on Sep 29, 2020 at 20:59 UTC
    Oops, no, it doesn't, but I think it should!

    Is that a bug in perl?

      I tried turning
      use re 'debug';
      on and comparing the output with
      /((.)(?:\2(*SKIP)){$len,})/g
      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]
        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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-03-29 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found