Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Find Length Of Longest Ascending/Descending Sequence

by Ratazong (Monsignor)
on May 10, 2011 at 09:22 UTC ( [id://903931]=note: print w/replies, xml ) Need Help??


in reply to Re: Find Length Of Longest Ascending/Descending Sequence
in thread Find Length Of Longest Ascending/Descending Sequence

nice feature :-)

How will it match data like the following?

11101234567890123411111 => expected result: 15
Will you need to create the pattern in <*0123456789> dynamically based on the length of the data?

Rata

Replies are listed 'Best First'.
Re^3: Find Length Of Longest Ascending/Descending Sequence
by moritz (Cardinal) on May 10, 2011 at 09:50 UTC
    Notice the repetition:
    <*0123456789> ** <?after 9>

    is short for

    <*0123456789> [ <?after 9> <*0123456789>]*

    So if it matches the first one, and upto 9 (that's what the <?after 9> checks), it tries again to start with 0.

    To extract the longest match, you need to collect all, and overlapping (because the last digits of an ascending sequence can be the first of a descending sequence):

    my regex seq { ... } my $length = [max] $teststring.match(&seq, :g, :overlap)>>.chars;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2024-04-24 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found