use strict;
my $str = 'X-91-55-72-X-X-X-90-71-91X
X-91-55-72-X-X-X-90-82-XXX
X-91-55-72-X-X-X-90-82-XX7
X-91-55-72-X-X-X-90-82-X91
X-91-55-72-X-X-X-90-82-90
X-91-55-72-X-X-X-90-82-X91
X-91-55-72-X-X-X-90-82-917
X-91-72-X-X-X-90-82-917
Number of delimiters (8) incorrect
X-91-55-7-X-X-X-90-82-91X
7 in first 9 is invalid
X-91-55-72-X-X-X-X94-82-91X
X94 in first 9 is invalid
X-91-55-72-X-X-X-90-82-X
last = X is not valid
X-91-55-72-X-X-X-90-82-XX
last = XX is not valid
X-91-55-72-X-X-X-90-82-XXXX
last = XXXX is not valid
X-91-55-72-X-X-X-90-82-X92
last = X92 is not valid
X-91-55-72-X-X-X-90-82-94
last = 94 is not valid
X-91-55-72-X-X-X-90-82-62X
last = 62X is not valid
X-91-55-72-X-X-X-90-82-927
last = 927 is not valid
';
my $regex = qr/^(?=(?P<LE10>(?:0[0-9]|1[0-9]|2[0-8]|3[0-7]|4[0-6]|5[0-5]|6[0-4]|7[0-3]|8[0-2]|9[0-1])))?(?:(?:X|(?P>LE10))-){9}(?:XXX|XX\d|X?(?P>LE10)|(?:19|28|37|46|55|64|7|3|82|91)[X\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