use strict;
my $str = 'a20171217091011 = None instead of 2017-12-17 09:10:11
b20171217091011 = None instead of 2017-12-17 09:10:11
20171217091011 = None instead of 2017-12-17 09:10:11
-20171217091011 = None instead of 2017-12-17 09:10:11
_20171217091011 = None instead of 2017-12-17 09:10:11
aa20171217091011 = None instead of 2017-12-17 09:10:11
a1-20171217091011 = None instead of 2017-12-17 09:10:11
123_20171217091011 = None instead of 2017-12-17 09:10:11
123 20171217091011 = None instead of 2017-12-17 09:10:11
123=20171217091011 = None instead of 2017-12-17 09:10:11
201712170910110 = 2017-12-17 09:10:11 instead of None
a20171217091011a = None instead of 2017-12-17 09:10:11
(20171217091011) = None instead of 2017-12-17 09:10:11
a-20171217091011 b = None instead of 2017-12-17 09:10:11
123(20171217091011)456 = None instead of 2017-12-17 09:10:11
20171217091011 = None instead of 2017-12-17 09:10:11
2017 20171217091011 2017 = None instead of 2017-12-17 09:10:11
20171218-20171217091011-070809 = 2017-12-18 20:17:12 instead of 2017-12-17 09:10:11
123(20171217-091011)456 = None instead of 2017-12-17 09:10:11
a2017(20171217 091011)b = None instead of 2017-12-17 09:10:11
2017xx(20171217?091011)cc2017 = None instead of 2017-12-17 09:10:11
A-20171116-080910-20171217091011 = None instead of 2017-11-16 08:09:10';
my $regex = qr/(?<!\d)20\d{6}\D?\d{6}(?!\d)/p;
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