← Back to all regex patterns
Replace
Low backtracking risk

Regex to Strip Non-Digits

This is useful when cleaning phone numbers, account references, or IDs into a digits-only form before formatting or validation.

Regex
/\D+/g

Try this pattern

Matches current input
(555) 123-4567

3 matches found in the current text.

Passing examples

  • (555) 123-4567
  • INV-2025-0042

Failing examples

  • 123456
  • 007

Code examples

JavaScript
const regex = /\D+/g;
regex.test(input);
Python
import re
pattern = re.compile(r"\D+")
bool(pattern.search(input))
Go
re := regexp.MustCompile("\\D+")
matched := re.MatchString(input)

Related Replace Patterns