Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Is this a bug in perl regex engine or in my brain?

by Athanasius (Archbishop)
on Oct 06, 2015 at 16:05 UTC ( [id://1143942]=note: print w/replies, xml ) Need Help??


in reply to Is this a bug in perl regex engine or in my brain?

Hello nikmit,

This (as expected) matches digits in the range 1-249.

But it also matches 00, 01, 02, etc. This is easily fixed by removing the first ? quantifier:

my $regex = '(2[0-4]|1[0-9])?[0-9]';

But I would rather use qr here, together with the /x modifier to make it easier to read:

my $regex = qr{ ( 2[0-4] | 1[0-9] )? [0-9] }x;

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Is this a bug in perl regex engine or in my brain?
by Crackers2 (Parson) on Oct 06, 2015 at 17:49 UTC
    Your regex no longer matches 10-99. You'd need something like
    my $regex = '(2[0-4]|1[0-9]|[1-9])?[0-9]';
    to fix that.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-19 10:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found