const regex = new RegExp('\\b(?:loan)\\s*(?:balance|amounts?|reimbursements?|installments?)?\\s*(?:of|is|\\s|\\:|\\-)\\s*(?:(?:[\\$]\\s*[\\.,\\d]+\\s*(?:millions?|billions?|thousands?|[KMB])?)|(?:[\\.\\,\\d]+\\s*(?:millions?|billions?|thousands?|[KMB])?\\s*(?:dollars?|\\$)?)|(?:[\\.\\,\\d]+\\s*(?:\\$)))|(?: [\\$]\\s*[\\.,\\d]+\\s*(?:millions?|billions?|thousands?|[KMB])?)|(?:[\\.\\,\\d]+\\s*(?:millions?|billions?|thousands?|[KMB])?\\s*(?:dollars?|\\$ ))|(?:[\\.\\,\\d]+\\s*(?:\\$ ))', 'gmi')
const str = `loan balance is \$45,56.89
loan balance of \$ 1M
Loan Amount of 43000K
loan reimbursement is 54.4 dollars
loan reimbursement is 34,10.45 million
loan balance of 25000\$
loan amount \$100,200.30
Loan Amount: 100K
Loan Amount \$ 1.5 million
loan is \$54K
loan balance - 50K\$
----------------------------------------------------------------
2.9 millions
\$25000.50
1,99\$
\$25000
1.10 dollar \$25000
1,99 dollars \$23K
\$ 25,00
1.10 dollar \$25,000.50
1,99 dollars \$25000.50
10 dollar
\$ 25,000
1.99\$
1,99\$
\$25000
1.10 dollar \$25000.50
1,99 dollars
10 dollar
\$ 25,000
25,000.50\$
1.99\$
\$25,000.50
1.10 dollar \$25000.50
1,99 dollars \$23K
10 dollar \$25000
1.99\$
\$ 25,000
djkb_09\$kjh87
gh67_(\$67.67P)
`;
// 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