use strict;
my $str = '23/02/1993
23-02/1993
23-fev-1993
fev-23-1993
fev.02.93
28-OCT-90
28-OCT-1990
10/28/90
10/28/1990
28.10.90
dd.mm.yyyy
28.10.1990
90/10/28
yyyy/mm/dd
1990/10/28
4 Q 1990
OCT 90
OCT 1990
01:02
01:02:34.75
02:34
02:34.75
20 08:03
20 08:03:00
20-JUN-1990 08:03
20-JUN-1990 08:03:00
1990-06-20 08:03
1990-06-20 08:03:00.0';
my $regex = qr/^\d{1,2}([ -.\/])(\d{1,2}|[a-zA-z]{3,15})(?1)\d{2,4}( \d{2}:\d{2}(:\d{2}([.:]\d)?)?)?$|^(\d{1,2}|[a-zA-z]{3,15})([ -.\/])\d{1,2}(?7)\d{2,4}( \d{2}:\d{2}(:\d{2}([.:]\d)?)?)?$|^\d{2,4}([ -.\/])(\d{1,2}|[a-zA-z]{3,15})\d{1,2}(?11)( \d{2}:\d{2}(:\d{2}([.:]\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