December 2023
Intermediate to advanced
242 pages
5h 28m
English
| Recipe 69 | Matching Formatted Numbers with Thousand Separators |
Suppose you are developing a price comparison app to assist users in comparing product or service prices across various online retailers. Since prices often include thousand separators, you find yourself in need of a regex pattern that can accurately detect numbers with thousand separators.
So, if a website lists the product like this:
| | Great deal! $7,499 %20 Price drop |
Your regex should be able to extract 7,499.
To extract numbers with thousand separators, you can use this function:
| | function extractNumbers(str) { |
| | const re = /\d{1,3}(?:,\d{3})*(?:\.\d+)?/g; |
| | return str.match(re)[0]; ... |
Read now
Unlock full access