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

Re: Why doesn't this regex work?

by Laurent_R (Parson)
on Aug 15, 2013 at 10:16 UTC ( #1049544=note: print w/ replies, xml ) Need Help??


in reply to Why doesn't this regex work? (Solved!)

In your data, the third (and fourth and fifth) digits from the right are the same. And this is what you are capturing. You will not get any match where the captured numbers are different.

Second thing, I think you should probably make your spaces optional if you do not have spaces at the beginning or at the end of your lines (or perhaps use a word boundary anchor).

With these two points in mind:

DB<8> $_ = "105 106 107 108 109 110 111 112 113 213 214"; DB<9> s[\s?(\d+)\d\d\K\s(?=(\d+)\d\d\s?)]{$1 + 1 == $2 ? "\n" : ' '} +ge; DB<10> x $_ 0 '105 106 107 108 109 110 111 112 113 213 214' DB<11>

I also think that this:

$1 + 1 == $2 ? "\n" : ' '

is going to fail on sequence jumps, e.g. on data looking like this:

$_ = qw /105 106 107 108 109 110 111 112 113 313 314/;


Comment on Re: Why doesn't this regex work?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-09-23 11:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (219 votes), past polls