use strict;
my $str = '3
999
-3
0
0.0
1.90
0.1
.01
-0.0000000000000000000000000000000001
2e3
-2e3
2e-3
-2e-3
1.0e0
0.1e1
.01e-1
-9.1e3
-9.1e-3
9E5
0e-11
0xff
0XFF
0x0
0xfe3
-0
-0.0
-0.0000000000000000000000000000000000
-.0
-.0000000000000000000000000000000000
1xff
0x
0x0fg3
0xf4.
.0xf
0xfe-3
-0xff
0.0xff
0xff.1
e89
.e3
001
-00.2
3.
a
-1
--1
-.1
2..3
2-
2...3
2.4.3
5-6-7
.-1';
my $regex = qr/^-?(0|[1-9]\d*)(?<!-0)$/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