const regex = /\b\d{1,3}(?:,\d{2,3})*(?:,\d{3})*(?:\.\d+)?\b/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\b\\d{1,3}(?:,\\d{2,3})*(?:,\\d{3})*(?:\\.\\d+)?\\b', '')
const str = `problem satatement is to get all the amount despite of inconsistencies in comma or dollar sign also I need to exclude year from that (if no pattern can be made asssume to get all the amount greater than 3000)
\$ 1,000,000.6522
\$ 3,500,000
90,00,00,000
5000000
200
200,000
20,00,000
1,000
\$ 4,000,000 for the 2023
800,000
90.65
5,555
5000
2021 --------this should be excluded from the pattern
89jfe90ABI900 ----this also should be excluded from the pattern`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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