|
Prev: FAQ 2.6 What modules and extensions are available for Perl? What is CPAN? What does CPAN/src/... mean?
Next: Help with Code
From: Tad McClellan on 28 Sep 2006 09:42 joez311(a)yahoo.com <joez311(a)yahoo.com> wrote: > I want to > match on the date went its formated like mm/dd/yy. print "$_ looks like a date\n" if m#^\d\d/\d\d/\d\d$#; # untested > I was trying: > /[0,1][0-9]/[0-3][0-9]/[0-9[0-9]/ ^^^^^ ^^ where is the closing square bracket? ^^^^^ matches any one of *three* characters, it will match a comma... > but my match doesn't seam to work as expected. I think its because of > the / used to split the feilds. Either put a backslash in front of the slashes, or use an alternate delimiter for the match operator. -- Tad McClellan SGML consulting tadmc(a)augustmail.com Perl programming Fort Worth, Texas
From: it_says_BALLS_on_your forehead on 28 Sep 2006 15:26 Dr.Ruud wrote: > joez311(a)yahoo.com schreef: > > > 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. Could some one show me the correct way > > to pattern match on this? > > Thanks, > > Zim > > > I see a comma that probably shouldn't be there, and a missing "]", and > unescaped slashes, which leads to: > > m~[01][0-9]/[0-3][0-9]/[0-9][0-9]~ > one issue with the OP's regex (even after it's been "corrected") is that it matches months 13 - 19, and days 32 - 39 (and also day 31 for months that don't have that particular day). > > > Check out Regexp::Common > http://search.cpan.org/search?module=Regexp::Common
From: Brian McCauley on 28 Sep 2006 17:07 joez311(a)yahoo.com wrote: > Hi, > 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. Well yes the unescaped / would be a problem if you are also using it as your pattern demiliter. As would the missing ] And I somehow doubut you really want to allow the first character to be a comma. Fix all that and your pattern will still match 19/39/06 So why not simply m{\d\d/\d\d/\d\d}? Fundamentally though you have an insummountable problem trying to match a date only when it's fomatted mm/dd/yy since there are strings like "01/02/03" that look like valid dates in yy/mm/dd or dd/mm/yy format too. Perhaps if we knew what you really wanted to do...
From: Dr.Ruud on 28 Sep 2006 20:14
it_says_BALLS_on_your forehead schreef: > Dr.Ruud: >> joez311: >>> 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. Could some one show me the >>> correct way to pattern match on this? >> >> I see a comma that probably shouldn't be there, and a missing "]", >> and unescaped slashes, which leads to: >> >> m~[01][0-9]/[0-3][0-9]/[0-9][0-9]~ > > one issue with the OP's regex (even after it's been "corrected") is > that it matches months 13 - 19, and days 32 - 39 (and also day 31 for > months that don't have that particular day). That was the main reason for this advice: >> Check out Regexp::Common >> http://search.cpan.org/search?module=Regexp::Common -- Affijn, Ruud "Gewoon is een tijger." |