const regex = /(NUMBER[(](\d{1,3},\d)[)])|(NUMBER[(]((\d{1,3})|(\d{1,3}[,]\d))[)]((?=\/DECIMAL)|(?=\/PERCENTAGE)).*)/gi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(NUMBER[(](\\d{1,3},\\d)[)])|(NUMBER[(]((\\d{1,3})|(\\d{1,3}[,]\\d))[)]((?=\\\/DECIMAL)|(?=\\\/PERCENTAGE)).*)', 'gi')
const 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
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions