SPUG: RE question

Menton, Stephen stephen.menton at cingular.com
Wed Nov 16 17:15:48 PST 2005


ParseDate from CPAN module Date::Manip might save you time... If you
can't CPAN it then I'd recommend something long but clear for your own
supportability's sake to match alll the patterns you wish to support.

In other news, your example say "for $thing" but your match checks
"$line". I'm also noticing a lack of "my", heh. Strict and -w are your
friends! ;-)

steve

-----Original Message-----
From: spug-list-bounces at pm.org [mailto:spug-list-bounces at pm.org] On
Behalf Of Duane Blanchard
Sent: Wednesday, November 16, 2005 17:06
To: spug-list at pm.org
Subject: SPUG: RE question


Hello All,

I want to match any one of three formats for dates in a file. I think I
understand the long way to do this, but know there must be a better, or
at least more clever, way to do it. I'm trying the following with no
success. I know it won't work the way I'm trying, but it gives you an
idea of what I am thinking of. What do you guys think? Some dates have
extraneous spaces and some have commas where wouldn't expect them or
don't where I would.

Thanks,

Duane

$RE_year = "(19|20)\d\d";
$RE_month =
"(jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|jun(e)?|jul(y)?|aug(ust)?
|sep(tember)?|oct(ober)?|nov(ember)?|dec(ember)?)";
$RE_day = "[0-3]?\d";

@array = ("1993 Mar  3", "1993  Mar 15", "Mar 15, 1993", "15 Mar 2001",
"2001, 15 Mar");

foreach $thing (@array)
{
	# in the first disjunction, find any one of the defined REs, in
the second, find any but the first one you found, etc.
	if ($line =~
/($RE_year|$RE_month|$RE_day),?\s*([^$1]($RE_year|$RE_month|$RE_day)),?\
s*([^$1$2]($RE_year|$RE_month|$RE_day)))
	{print "You got a date: too bad it isn't with a girl.";}
}
--
Duane Blanchard
206.280.1263

There are 10 kinds of people in the world;
those who know binary and those who don't.
_____________________________________________________________
Seattle Perl Users Group Mailing List  
     POST TO: spug-list at pm.org
SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
    MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med
    WEB PAGE: http://seattleperl.org/


More information about the spug-list mailing list