use strict;
my $str = 'd_MON_02
rd
rd_029
rd_MON
rd_MON_01
rd_MON_01+007
rd_WED_03-007
rm_JAN_d29
rm_01_d29
rm_JAN_MON02
m_JAN_MON01
rm_JAN_MON
one off second Monday
repeat daily
repead daily on the 29th
repead daily on Monday
repeat first Monday
repeat second Monday with offset of 7 days
repeat second Wednesday with negative offset of 7 days
repeat on 29th of January with 3 characters month name format
repeat on 29th of January with 2 digit numbering month format
repeat second Monday of January
one off first Monday of January
repeat all Mondays in January';
my $regex = qr/^((((r?d_(MON|TUE|WED|THU|FRI|SAT|SUN))_?([0][1-5])?(([-+])([0-9]{3}))?)|(r?d_[0-9]{3}))|rd|((r?m_((JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)|([0][1-9]|[1][0-2])))_?((d[0-9]{2})|(MON|TUE|WED|THU|FRI|SAT|SUN)_?([0][1-5])?)))$/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