Re: matching date
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 28 Sep 2006 11:03:03 -0700
joez...@xxxxxxxxx wrote:
Can someone help me out with the following pattern match? I want to
match on the date went its formated like mm/dd/yy. I was trying:
/[0,1][0-9]/[0-3][0-9]/[0-9[0-9]/
but my match doesn't seam to work as expected. I think its because of
the / used to split the feilds.
You have multiple problems.
1) if you use / as the delimiter, you have to escape (that is, precede
with a backslash) any actual / characters that you want to match.
2) commas match themselves in character classes. A character class is
either a list (with nothing separating the elements) or a range (using
the - character) or a combination of both
3) Not all of your character classes are terminated
4) The character class [0-9] is more easily written \d
Putting those together:
m/[01]\d\/[0-3]\d\/\d\d/;
However, this is still not sufficient to match a real date, as it would
allow a date of, for example,
19/38/04;
Could some one show me the correct way
to pattern match on this?
The correct way is to not reinvent the wheel:
use Regexp::Common qw/time/;
/$RE{time}{mdy}/;
to allow any month-day-year pattern, or
/$RE{time}{m2d2y2}/
to specify exactly two digits for each field.
Paul Lalli
.
- References:
- matching date
- From: joez311
- matching date
- Prev by Date: Re: using http::recorder
- Next by Date: Re: matching date
- Previous by thread: Re: matching date
- Next by thread: Re: matching date
- Index(es):
Relevant Pages
|