use strict;
my $str = '############# valid ##########
12
12a
12A
12 A
12 a
12 b
12 z
121 b
56/58
56/58a
56-58
56 - 58
56-58a
1234
1234 a
56/58a
18a - 19b
18a-19b
############# not valid ##########
12345
25-ab
12ü
12_
asdfghjklöqwertzuioyxcvbnm
12!"§$$%&/()
a2
a2
13àâäèéêë
0
123aaa123,
123 aaa 123
1 a 1
1a 1\'
1a1
13àâäèéêë
00 a
a a
00a
0a
12 ab 12';
my $regex = qr/^[1-9]\d{0,3} ?[a-zA-Z]?(?: ?[/-] ?[1-9]\d{0,3} ?[a-zA-Z]?)?$/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