SPUG: RE question
Duane Blanchard
dblanchard at gmail.com
Wed Nov 16 17:05:50 PST 2005
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.
More information about the spug-list
mailing list