use strict;
my $str = 'following day of the month next preceding an interest payment date
these day of the month next preceding an Interest Payment Date (each a "Record Date")
last day of the month preceding any Bond Payment
record date shall be defined as the fifteenth (15 th ) day preceding any interest payment date.
The Record Date is the last calendar day of the month preceding each Interest Payment Date, whether or not such day is a Business Day.
calendar month immediately preceding an interest payment
calendar month next preceding each Interest Payment Date.
(whether or not a business day) of the calendar month before the interest payment
interest payable on the Bonds on any interest payment date means the close of business on the 15th day of the preceding month.
month prior to an Interest Payment
day preceding any interest payment
immediately preceding an interest payment date';
my $regex = qr/(?<!last calendar) day (of the month )?(next )?(preceding|prior to) (any|an|each) (interest|Bond) payment/mip;
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