The \D metacharacter matches any single character that is not a digit from 0 through 9. It is the inverse of \d, equivalent to [^0-9], and essential when you need to isolate letters, strip formatting from phone numbers, or validate text-only input.
01
Non-digit
\D
02
Shorthand
[^0-9]
03
Inverse
Opposite of \d
04
Quantifiers
\D+
05
Strip
replace(/\D/g, "")
06
Validate
/^\D+$/
Fundamentals
Introduction
Real-world strings rarely contain digits alone. Product codes, usernames, and formatted phone numbers mix letters, symbols, and numbers. The \D metacharacter lets you target everything that is not a numeral.
One \D matches exactly one non-digit character. To match a full word or symbol run, combine \D with quantifiers like + (one or more) or use the global flag with replace() to remove every non-digit at once.
Concept
Understanding the \D Metacharacter
\D is a negated predefined character class escape. In JavaScript it matches any character except ASCII digits 0 through 9.
Pair \D with anchors (^, $), quantifiers (+, *), and the global flag for bulk removal or extraction.
Foundation
📝 Syntax
JavaScript
\D // one non-digit character
\D+ // one or more non-digits
\D* // zero or more non-digits
/\D/g // global: every non-digit
\d // one digit (inverse of \D)
Common patterns
/\D+/ — match a run of non-digit characters (words, symbols).
/^\D+$/ — validate that the string contains no digits.
/\D/g with replace("", ...) — strip all non-digits.
/\d|\D/ — match either a digit or a non-digit (any character).
Cheat Sheet
⚡ Quick Reference
Goal
Pattern
One non-digit
\D
Non-digit sequence
\D+
No digits in string
/^\D+$/
Remove non-digits
/\D/g + replace("", ...)
Same as \D
[^0-9]
Opposite
\d
Compare
📋 \D vs [^0-9] vs \d
Three related patterns for non-digits and digits.
Non-digit
\D
Shorthand
Class
[^0-9]
Equivalent
Digit
\d
Inverse
Many non-digits
\D+
Quantifier
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it links. Examples cover detection, extraction, digit stripping, validation, and parsing mixed IDs.
📚 Getting Started
Detect whether a string contains any non-digit character.
Example 1 — Test for Any Non-Digit
Return true when at least one letter, space, or symbol appears in the text.
The global flag with /\D/g replaces every non-digit with an empty string. Digits remain untouched—one of the most common \D patterns in production code.
Example 4 — Validate Text With No Digits
Ensure input contains only non-digit characters (letters and symbols).
For letters only (excluding digits and symbols), use /^[a-zA-Z]+$/ instead of /^\D+$/.
Combine with \b for word tokens: \b\D+\b matches non-digit words.
Compatibility
Browser & Runtime Support
The \D non-digit metacharacter is part of core JavaScript regular expression syntax.
✓ Baseline · ES3+
RegExp \D
Supported in every browser and Node.js version. \D and [^0-9] behave identically for ASCII non-digits.
99%Universal syntax
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
\DExcellent
Bottom line: Safe everywhere. Use \D as the standard shorthand for matching non-digits.
Wrap Up
Conclusion
The \D metacharacter is the fastest way to match non-digits in JavaScript regular expressions. It covers letters, spaces, punctuation, and symbols—everything except 0 through 9.
Use \D+ to extract text runs, /\D/g with replace() to normalize formatted numbers, and remember that it is the uppercase inverse of \d. Next, learn \S for non-whitespace matching.
Use \D+ to extract letter sequences from mixed text
Anchor with ^ and $ for digit-free validation
Know that \D and [^0-9] are equivalent
Pair with \d when parsing structured codes
❌ Don’t
Expect \D alone to match multi-character words
Forget the global flag when removing all non-digits
Assume /^\D+$/ means “letters only”
Assume Unicode numerals are excluded without the u flag
Mix \D and manual [^0-9] randomly in one project
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about RegExp \D
Match anything except digits 0 through 9.
5
Core concepts
🚫01
Non-digit
\D
Syntax
📝02
= [^0-9]
Same set.
Compare
📈03
\D+
Sequences.
Quantifier
🔒04
/\D/g
Strip chars.
Replace
🔢05
\d
Inverse.
Pair
❓ Frequently Asked Questions
\D matches any single character that is NOT an ASCII digit (0 through 9). Letters, spaces, punctuation, and symbols all satisfy \D.
Yes. For standard JavaScript regex without the u (Unicode) flag, \D and [^0-9] are equivalent—they both match one non-digit character.
\d matches digits 0–9. \D is the uppercase inverse and matches everything except those digits. Together they partition the ASCII character set for basic parsing.
By itself, \D matches exactly one non-digit. Add a quantifier like + for one or more (\D+) or * for zero or more (\D*) to match longer text runs.
Use replace with the global flag: str.replace(/\D/g, ""). Every non-digit is removed, leaving digits only—handy for phone numbers and formatted IDs.
The \D non-digit shorthand is core regex syntax since ES3. It works in every browser and Node.js version.
Did you know?
JavaScript provides uppercase inverses for three common shorthands: \D (not digit), \S (not whitespace), and \W (not word character). Uppercase always means “everything except” the lowercase form.