use strict;
my $str = '20000002000
200 0
(2022.xx2000.xx)
(2022.xx) 2000.xx
(2020-20)
(20xx-12)
(20xx.xx-11)
(2002-KW00.00)
(2002-KW00)
(2022.KWxx)
(2021.KW09)
(2021.KW09)
(2021.02)
2022.Qx
2032.Q4
(2020.xx)
2022-Q1
2022 Test
Test 20xx
20202020
.Qx
KW23
KWxx
(20xx)
(.-Q4)
2000-
2000.
';
my $regex = qr/\(20(\d{2}|x{2})((\.|-)([0-9]{2}|x{2}|KW(\d{2}|x{2})|Q(x|[1-4])|(([0-9]{2}|x{2})(\.|-)([0-9]{2}|x{2}))))?\)/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