const regex = /^\s*\$(\d{1,3}(?:,\d{1,3})*(?:\.\d{1,2})?)\s*-\s*\$(\d{1,3}(?:,\d{1,3})*(?:\.\d{1,2})?)\s*per\s+(?:annum|hour)\s*$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^\\s*\\$(\\d{1,3}(?:,\\d{1,3})*(?:\\.\\d{1,2})?)\\s*-\\s*\\$(\\d{1,3}(?:,\\d{1,3})*(?:\\.\\d{1,2})?)\\s*per\\s+(?:annum|hour)\\s*$', 'gm')
const str = `\$80,000,000,000.00 - \$90,000,000,000.00 per annum
\$80,000,000 - \$90,000,000 per annum
\$80,000 - \$90,000 per annum
\$20 - \$24.99 per hour
\$20 - \$24.99 per hour
\$20 - \$24.99 per hour
\$20.00 - \$24.99 per hour
\$20.00 - \$24.99 per day
\$111,120.00 - \$11,124.99 per week
\$111,222,120.00 - \$111,111,124.99 per months`;
// 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