[^0-9] is a negated character class. It matches exactly one character that is not an ASCII digit 0–9. The ^ must be the first character inside the brackets to mean “not.”
Remember
/[^0-9]/ → one non-digit (letter, space, symbol, …)
/[0-9]/ → one digit (the opposite class)
/[^0-9]+/ → one or more non-digits
/\D/ → same idea as [^0-9] (shorthand)
"A1!".match(/[^0-9]/g) → ["A", "!"]
^ inside [] → negate the class
^ outside [] → start-of-string anchor
Write the class in a regex, then use test, match, or replace.
Write /[^0-9]/ (add g to find every match).
Use test() to check if any non-digit exists.
Use match() to collect non-digit characters.
Use replace(/[^0-9]/g, "") to strip non-digits and keep numbers.
Piece
Required?
Role
[^0-9]
Yes
One character that is not 0–9
Quantifier (+, *, …)
Optional
Match a run of non-digits
Flag g
Optional
Find / replace all matches
Pseudocode
Pseudocode
pattern = [^0-9] // "not digit 0–9"
for each character c in text:
if c is NOT in {0,1,2,3,4,5,6,7,8,9}:
c matches
else:
c does not match
// with + : match the longest run of such characters
Reference
Cheat Sheet
Keep these facts handy while writing digit / non-digit patterns.
Topic
Detail
Syntax
/[^0-9]/
Meaning
One character that is not 0–9
Shorthand
\D (same for basic ASCII digits)
Opposite
[0-9] or \d
One or more
/[^0-9]+/
Strip non-digits
str.replace(/[^0-9]/g, "")
Standard
Core regex (ES3+) — universal support
Try it
Live Preview
Pick a sample string and see every match of /[^0-9]/g.
Browser demo of /[^0-9]/g — same idea as the examples below.
Caret:^ inside [] negates; outside it anchors the start.
One line:[^0-9] means “not a digit” — the inverse of [0-9], and a clear twin of \D.
Frequently Asked Questions
[^0-9] is a negated character class that matches exactly one character that is NOT an ASCII digit 0–9. The caret ^ inside the brackets means “not these characters.”
Yes, for standard JavaScript regex without the Unicode (u) flag. Both match one non-digit. Prefer whichever reads clearer in your pattern.
By itself it matches one character. Add a quantifier such as + (one or more) or * (zero or more): /[^0-9]+/ matches a run of non-digits.
[0-9] matches a digit. [^0-9] matches any single character that is not a digit. The leading ^ inside [] negates the class.
Use replace with the global flag: str.replace(/[^0-9]/g, ""). Every non-digit is removed, leaving digits only.
No. Outside brackets, ^ means start of string (or line with m). Inside brackets at the start of the class, ^ means “not.”