use strict;
my $str = '120x200mm matches
12.2x200.3mtrs matches
2x21x21cm // needs to match
100\\\' X 130\\\'
4 acres
0.54
0.488 (90x223)/ GIS0.78
90x160
100x149.7x123
143.76 X 453.52
6.13 per tax bill
120x378 per tax roll';
my $regex = qr/(?<!-)((\d+(\.\d+)?))(\s*[xX]\s*\d+(\.\d+)?){1,2}\s*(mm|cm|mtrs|ft|yd)/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