Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: need regular expression

by ioannis (Priest)
on Nov 02, 2005 at 08:23 UTC ( #504866=note: print w/ replies, xml ) Need Help??


in reply to need regular expression

for ( my @dates = qw( 4-10-31 14-11-31 ) ) { s/ ^ (\d) (\d)? (-\d{1,2}-\d{1,2}) $ /($2?"20$1":"200").$1.$+/ex and print; }


Comment on Re: need regular expression
Download Code
Re^2: need regular expression
by ioannis (Priest) on Nov 02, 2005 at 10:55 UTC
    This formula is simpler than the one earlier. The main insight here is to avoid strings; it is better to use arithmetic addition to construct the 'year' string (i.e. 20xx) .
    for ( my @dates = qw( 4-10-31 14-11-31 ) ) { s/ ^ (\d{1,2}) ((?:-\d{1,2}){2}) $ /(2000+$1).$+/xe and print; }
      I prefer to use strings - in that case, it becomes easy to deal with 3 or 4 digit years as well:
      my @dates = qw /4-10-31 14-11-31 1979-10-10/; for (@dates) { s/(\d+)/substr("2000", 0, -length($1)).$1/e; print "$_\n"; } __END__ 2004-10-31 2014-11-31 1979-10-10
      Perl --((8:>*

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-12-20 16:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (96 votes), past polls