Blog
Text tools

Extract digits from text

Paste your text and every digit 0-9 is pulled out into a single result, discarding letters, punctuation and everything else. Useful for getting the raw digits out of a formatted phone number, invoice code or serial number. Turn on "keep spaces" to preserve the gaps between digit groups instead of joining them into one unbroken string.

Result

Digits found —

All calculations run locally in your browser: parsing, chart, export. Disconnect the network and the page keeps working.

Facts and limits of this method

Extracted Digits 0-9 only
Discarded Letters, punctuation, spaces (unless kept) and any other characters
keepSpaces off (default) All digits are joined into one continuous string with no separators
keepSpaces on Original spaces between digit groups are kept, collapsed to single spaces, ends trimmed
Full-width digits 0-9 and similar are outside 0-9 — not extracted
Processing Runs locally in the browser, nothing is sent to a server

When it misleads you

How it is calculated

With "keep spaces" off, the tool runs text.replace(/\D/g, "") — removing every character that is not a digit — leaving a single unbroken string of all the digits found, in their original order.

With "keep spaces" on, the tool first removes everything except digits and whitespace, then collapses any run of remaining whitespace into a single space and trims the ends — so groups of digits that were originally separated by a space stay visually separated, other punctuation between them does not survive.

Either way, only the ten ASCII digits 0-9 are treated as digits. Letters, punctuation, symbols and non-ASCII digit forms are all discarded regardless of the spacing option.

"Digits found" counts the digit characters present in the final result — it equals the total number of 0-9 characters in the original text, since digits are never removed once matched, only rearranged relative to whitespace.

Questions and answers

What does the "keep spaces" option actually preserve?

Only spaces — the whitespace that originally separated groups of digits. Dashes, dots, parentheses and other punctuation between digits are always discarded, whether or not this option is on.

Can I use this to pull a phone number out of a sentence?

Yes — it will extract the raw digits, but strips the formatting (dashes, parentheses, plus sign). With spacing on you'll keep rough groupings if the original had spaces; without it, everything joins into one string.

Does it extract full-width or superscript digits?

No, only plain ASCII 0-9. Full-width digits (0-9) and superscript/subscript forms are outside that set and are discarded, not extracted.

What happens with multiple separate numbers in the text?

Without spacing, they merge into one string with no way to tell them apart. With spacing on, they stay separated wherever the original text had a space between them.

Is my text sent anywhere?

No. The whole operation runs in your browser; the text is never transmitted anywhere.

Related tools

All tools