Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const regex = /[0-9][+-]?[0-9]{1,3}(?:,?[0-9]{3})*(?:\.[0-9]{2})?/g;
- // Alternative syntax using RegExp constructor
- // const regex = new RegExp('[0-9][+-]?[0-9]{1,3}(?:,?[0-9]{3})*(?:\\.[0-9]{2})?', 'g')
- const str = `\$20,000.00 USD`;
- 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}`);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement