use strict;
my $str = 'NUMBER(12)
NUMBER(12)/NUMBER
NUMBER(1)
NUMBER(1)/NUMBER
(100)
DATATYPE=NUMBER
NUMBER
NUMBER()
NUMBER(10,2)/PERCENTAGE
NUMBER(12)/DECIMAL
NUMBER(12,4)
NUMBER(13,4)
NUMBER(15)/DECIMAL
NUMBER(15,2)
NUMBER(16)/DECIMAL
NUMBER(10,3)/DECIMAL
NUMBER(3)/DECIMAL
NUMBER(3)/PERCENTAGE
NUMBER(4)/DECIMAL
NUMBER(4,1)
NUMBER(4,2)
NUMBER(5)/DECIMAL
NUMBER(5)/PERCENTAGE
NUMBER(5,2)
NUMBER(5,2)/PERCENTAGE
NUMBER(6)/DECIMAL
NUMBER(7)/DECIMAL
NUMBER(8)/DECIMAL
NUMBER/
NUMBER/CURRENCY
NUMBER/DECIMAL
NUMBER/IFS CURRENCY
NUMBER/INVISIBLE
NUMBER/NUMBER
NUMBER/PERCENTAGE
NUMBER/UPPERCASE
NUMBER=
Number
number
';
my $regex = qr/(NUMBER[(](\d{1,3},\d)[)])|(NUMBER[(]((\d{1,3})|(\d{1,3}[,]\d))[)]((?=\/DECIMAL)|(?=\/PERCENTAGE)).*)/ip;
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