use strict;
my $str = 'March 9 12:31 AM and March 10 7:30 AM
March 11 7:30 AM and March 12 10:30 AM
Mar 31 9:00 PM and Apr 1 12:39 AM
March 31 10:11 PM and April 1 5:23 AM
7:45 PM and 10:30 PM
May 3 4:41 PM PDT and May 4 12:19 AM PDT
March 31 10:71 PM and April 1 5:23 AM
27:45 PM and 10:80 PM
May 3 4:41 PM PDT and May 41 12:19 AM PDT';
my $regex = qr/((?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|(Nov|Dec)(?:ember)?)(\s)([1,2][\d]|[1-9]|30|31)(\s))?(\b[\d]|10|11|12):[0-5][0-9]\s(AM|PM)/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html