PatternRegex
Match numbers with thousand separators
Pull out numbers formatted with comma thousand separators, like 1,000,000, from reports, invoices, or scraped text.
Last updated
Matches
- The budget is 1,000,000 dollars
- Population: 12,345 people
Doesn’t match
- The count was 1000000 today
- The code is 12,34 not thousands
Why it’s written this way
\d{1,3} matches the leading one-to-three digits, and the non-capturing group (?:,\d{3})+ then requires one or more repeats of a comma followed by exactly three digits, mirroring the Western convention of grouping from the right.
Word boundaries on both ends stop the match from starting or ending mid-run, so it won't grab just the tail of a longer plain number that happens to sit nearby.
Edge cases to know
- →It assumes Western thousands grouping. Indian-style lakh formatting like 1,00,000 breaks the three-digit assumption, and the pattern still latches onto the trailing 00,000 as if it were a valid group — a genuine false positive worth knowing about.
- →A plain unformatted number such as 1000000 is correctly ignored, but that also means the pattern can't help you find numbers that are missing their separators.