use strict;
my $str = ' a regular expression using C#/.Net that matches 1-4 alphanumerics followed by spaces, followed by 10 digits.
The catch is the number of spaces plus the number of alphanumerics must equal 4,
and the spaces must follow the alphanumerics, not be interspers
abcd1234567890 y
a 1234567890 y
ab 1234567890 y
1 1234567890 y
1 1234567890 n
1 1234567890 n
11234567890 n
a c 1234567890 n
a d1234567890 n
abcd 1234567890 n
';
my $regex = qr/\b(?!\w\s{1,2}\w+)\w(\w|\s){3}\d{10}/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