Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Why doesn't this regex work?

by Laurent_R (Priest)
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 avoiding work at the Monastery: (13)
As of 2014-04-17 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (453 votes), past polls