const regex = new RegExp('\\$(\\d{1,3}[\\.,]*)+', 'gm')
const str = `\$5.34
\$5,34
\$222,100,455.34
\$222.100.455,34
\$222,100,455
\$222.100.455
\$4,13 + \$5,24 = \$9,37
\$4,13 + \$1.005,24 = \$1.009,37
\$8.000 - \$8.000 = \$0
\$4.545,45 is less than \$5,454.54.
\$4,545.45 is less than \$5.454,54.
Our movie tickets cost \$12,20.
127.255.255.255
Clayton Kershaw \$31.000.000
Zack Greinke \$27.000.000
Adrian Gonzalez \$21.857.143
`;
// 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