use strict;
my $str = '01/01/20
02/01/20
03/01/20
04/01/20
05/01/20
06/01/20
07/01/20
08/01/20
09/01/20
10/01/20
11/01/20
12/01/20
01/32/20
01/03/20
01/04/20
01/05/20
01/06/20
01/07/20
01/08/20
01/09/20
01/10/20
01/11/20
01/12/20
01/13/20
01/14/20
01/15/20
01/16/20
01/17/20
01/18/20
01/19/20
01/20/20
01/21/20
01/22/20
01/23/20
01/24/20
01/25/20
01/26/20
01/27/20
01/28/20
01/29/20
01/30/20
01/31/20
';
my $regex = qr/^((0|1)[0-9])\/([0-3][0-9])\/([0-9][0-9])/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