Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

RE: Re: $1

by Odud (Pilgrim)
on Jun 21, 2000 at 17:50 UTC ( [id://19241]=note: print w/replies, xml ) Need Help??


in reply to Re: $1
in thread $1

I should have given an example of /x, here's how my version of your code that I used to try out my solution looks:

while (<>){ if(/( [0-3]?[0-9](?:th|st|nd|rd)?\s+ (?:Jan(uary)?|Feb(ruary)?|Mar(ch)?|Apr(il)?|May|Jun(e)?| Jul(y)?|Aug(ust)?|Sep(tember)?|Oct(ober)?|Nov(ember)?|Dec(embe +r?))\s+ [0-9]?[0-9]?[0-9][0-9]) /ix) { print "$1\n"; } }

Replies are listed 'Best First'.
RE: RE: Re: $1
by Ted Nitz (Chaplain) on Jun 21, 2000 at 19:38 UTC
    I like that regex more, but there are still a few minor changes I would make.
    while (<>){ if(/ ( [0-3]?[0-9](?:th|st|nd|rd)?\s+ # Get day (?: # Get month Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?| Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?| Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?| Nov(?:ember)?|Dec(?:ember)? )\s+ [0-9]{2,4} # Get Year ) /ix) { print "$1\n"; } }
    The (?:) things are just like normal ()'s except they don't capture to a variable, they just do grouping, helps the interpreter optimize the regex.

    The {x,y} means require atleast x of the previous item, and at most y. For refrence you can also say {x} which means require x of them, or {x,} which means atleast x.
    -Ted
      Oh I agree entirely - it was a just a quick solution to the problem, not an attempt at an optimal one. There's a date parser module available through CPAN which I would normally use. I don't know if it copes with 2nd, 4th, etc. though.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-16 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found