> Steve Massey wrote: > > > > using the following code.. I am looking to match any text that has a date in > > it ie 8-Nov, nut my code also matches 8-11b, which is not what I want > > > > help appreciated > > > > Steve > > > > > > ======== > > #! /usr/bin/perl -w > > > > $test = "8-11b1"; > > ##$test = "8-Nov1"; > > > > if ( $test =~ /(\d{1,2})\-(\w{3})([\d\w]*)/) { > > $day = $1; > > $month = $2; > > $rem = $3; > > print "result is $day..$month..$rem\n"; > > } else { > > > > print "result is $test\n"; > > } > > Hi Steve. > > This should do the trick: > > if ( $test =~ /(\d+)-([a-z]+)(.*)/i ) { > : > } >
While all of the responses provided are nice and may get you part of the way to solving the issue I would suggest backing up a couple of steps and telling us how strictly you want the date to be. I took from your original post that checking for a number followed by a dash followed by some letters isn't sufficient. Are you looking for that, or are you really looking for a date? Where a date has special qualities, such that the number on the front ranges from either 1 to 28, 29, 30, 31 and the month abbreviation corresponds to one of Jan, Feb, Mar, etc. Furthermore, are you looking for a date surrounded by other text, or have you already isolated the date, and want to examine it to be an "actual date"? Matching a "date" with a regexp is much more difficult than the suggested methods, I would suggest looking into either of these two CPAN modules: Date::Parse Date::Manip If your date is isolated, otherwise I would take a look at Mastering Regular Expressions from O'Reilly in particular there is a lengthy discussion on how to match an actual date similar to your format (and it is not pretty, well depending on how you look at it). Depending on what your actual goal is... http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]