use strict;
my $str = '29.02.1704
01.01.1987 // ok
101.01.19870 // bad- too many numbers
1.1.1987 // ok
32.02.1987 // bad- 32 feb
29.02.2001 // bad
0.0.1987 // bad
0.13.1987 // bad
8.8.8.8 // bad
31.04.1987 // bad
31.06.1987 // bad
31.09.1987 // bad
31.11.1987 // bad
30.02.1987 // bad
29.02/1987 // bad
29.02.1988 // ok
29.02.2000 // bad
29.02.2408
';
my $regex = qr/(?<day>0?[1-9]|[12][0-9]|3[01])(?>.{1})(?(?=0?[469]|11)(?<!31(?>.{1}))|)(?(?=0?2)(?<!3[01](?>.{1})))(?(?=0?2(?>.{1})\d\d(?!00)(?:[02468][048]|[13579][26]))|(?<!29(?>.{1})))(?<month>0?[1-9]|1[12])(?>.{1})(?<year>19[0-9][0-9]|20[0-9][0-9]|[0-9]{2,4})(?!\d)/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