Start free · Free tools · Fair usage limits
Browse Tools

Categories

Custom AI Solutions – AI2Flows
LIVE NEWS
Loading latest AI & SEO news…
Home›Tools›Regex Tester›Regex for number with thousands separators
Regex pattern · validation

Regex for number with thousands separators

Regex for number with commas: a tested pattern with examples, a plain-English breakdown, and code for JavaScript, Python, PHP, Java and Go.

Quick answer

Use /^\d{1,3}(?:,\d{3})*(?:\.\d+)?$/ as a number with thousands separators regex. It matches "1,000" and "1,234,567.89", and rejects "1,00" and "1234,567". Plain numbers without commas over 999 (1234) fail.

Last updated · Maintained by FreeAIToolz · How we test

/^\d{1,3}(?:,\d{3})*(?:\.\d+)?$/
  • 1,000matches
  • 1,234,567.89matches
  • 999matches
  • 12,345matches
  • 1,00no match
  • 1234,567no match
  • ,123no match
  • 1,234,56no match
Open in the full Regex Tester (replace, flags, groups) →

How this regex works

PartMeaning
^\d{1,3}1–3 leading digits
(?:,\d{3})*groups of exactly three digits after each comma
(?:\.\d+)?$optional decimals

Examples

InputResult
1,000✓ Matches
1,234,567.89✓ Matches
999✓ Matches
12,345✓ Matches
1,00✗ No match
1234,567✗ No match
,123✗ No match
1,234,56✗ No match

Every example above is checked automatically in JavaScript and Python each time the site is built.

Limitations and edge cases

Plain numbers without commas over 999 (1234) fail. Use ^(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$ to accept both.

When to use this pattern

Parsing human-formatted numbers from spreadsheets, invoices and scraped pages.

Use it in your language

JavaScript

const re = /^\d{1,3}(?:,\d{3})*(?:\.\d+)?$/;
re.test(input); // true or false

Python

import re
pattern = re.compile(r'^\d{1,3}(?:,\d{3})*(?:\.\d+)?$')
bool(pattern.search(value))

PHP

$ok = preg_match('~^\\d{1,3}(?:,\\d{3})*(?:\\.\\d+)?$~', $value) === 1;

Java

Pattern pattern = Pattern.compile("^\\d{1,3}(?:,\\d{3})*(?:\\.\\d+)?$");
boolean ok = pattern.matcher(value).find();

Go

re := regexp.MustCompile(`^\d{1,3}(?:,\d{3})*(?:\.\d+)?$`)
ok := re.MatchString(value)

More regex patterns

Frequently asked questions

What is the regex for number with thousands separators?
/^\d{1,3}(?:,\d{3})*(?:\.\d+)?$/. Plain numbers without commas over 999 (1234) fail. Use ^(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$ to accept both.
Which languages does this pattern work in?
It is tested in JavaScript and Python and uses syntax that also works in PHP (PCRE) and Java. It also works in Go’s RE2 engine.
Why does the pattern start with ^ and end with $?
They anchor the match to the whole string, so "abc1,000xyz" cannot pass just because it contains a valid part. To search for matches inside longer text, remove ^ and $ (use \b where word boundaries help) and add the g flag.