use strict;
my $str = ' -
+
- x 20\'-4"
+ 20\'
- 20\'
20\'3"
20\'-3"
20\' - 40"
-20\'-20"
20\'00"
20.45"
20.45\'
00.45\'
00.45"
00"
00\'
+20\' - 0.45"
20\' - .45"
.20\'-4"
0.30\'-4"
20\'
20\'P
20"
20"P
0.20\'
.20\'
a\'
b"
- 20 1/2\'
+ 20 22/128"
20 0/2"
20 00/12\'
-1/2"
+ 1/2\'
0/2"
00/22"
+ 01/2"
23 00/30\'
23 12/03\'
23 02/20"
0 2/3\'
00 2/3\'
- 11 2/3\'
2 22\'
2 22/03\'
2 3/2
23 00/30
23 12/03
23 02/20
23/34"
23/23.4"
asf sf"
';
my $regex = qr/^(\+ *|- *)?((?!0+)\d*?|(?!0{2,})\d*?\.(?!0+)\d*?)('|")$|^(\+ *|- *)? *(?!0+)\d+?' *-? *(\d+?|\d*?\.\d*?)"$|^((\+ *|- *)?((?!0+)|0 )\d*? *(?!0+)\d+?\/(?!0+)\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