Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: need help with a Perl regular expression

by davido (Cardinal)
on Jul 16, 2014 at 16:33 UTC ( [id://1093897]=note: print w/replies, xml ) Need Help??


in reply to need help with a Perl regular expression

/\d{2}-\d?\d{4}/
  • \d matches a digit.
  • {...} is a quantifier allowing you to specify an exact number of times its atom must match, or a range of legal number of times.
  • - is treated as a literal hyphen in this case.
  • ? as a quantifier specifies zero or one times.

It could probably be simplified to:

m/\d\d-\d{4,5}/

...since there's no real difference in this case between four digits with an optional leading extra digit, and four digits with an optional trailing extra digit.


Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-19 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found