I am writing a regex to find mutiple dates in a string if they exist, I have two formats and I dont know if there will one or two dates ahead of time When I run this I get the match for the first date NOT the second
The date formats can be:
Mar 11 08:02:08
Mar 11 08:02:08.32
Mar 11 2011 08:02:08
Mar 11 2011 08:02:08.32
$current_line = " Mar 11 08:02:08 172.28.17.253 Mar 11 2011 08:02:08 D +R-FW-1 :"; $current_line =~ m{ ( [A-Z]{1}[a-z]{2} #Month, 1 upper w\2 lower char [ ][ ]*? #one or more spaces [0-9][0-9]? #Day, one or more numbers [ ][ ]*? #one or more spaces [0-9]{2} #Hour, 2 digits [:] #delimeter, colon [0-9]{2} #Minute, 2 digits [:] #delimeter, colon [0-9]{2} #Seconds, 2 digits [.]? #decimal point if it exists [0-9]*? #Fracion of seconds if it exists )? #string may exist more than once .*? #Any text ( [A-Z]{1}[a-z]{2} #Month, 1 upper w\ 2lower char [ ][ ]*? #one or more spaces [0-9][0-9]? #Day, one or more numbers [ ][ ]*? #one or more spaces [0-9]{4} #Year, 4 digits [ ][ ]*? #one or more spaces [0-9]{2} #Hour, 2 digits [:] #delimeter, colon [0-9]{2} #Minute, 2 digits [:] #delimeter, colon [0-9]{2} #Seconds, 2 digits [.]? #decimal point if it exists [0-9]*? #Fraction of seconds if it exists )? #Date may exist more than once }gxms; if($1){ print "Date_1 = $1\n"}; if($2){ print "Date_2 = $2\n"};
In reply to regex for multiple dates by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |