The negated class [^abc] matches any single character except lowercase a, b, or c. It extends the negation idea from [^0-9] to a custom letter set—ideal for filtering, validation, and cleanup when certain characters must be excluded.
01
Negate
[^abc]
02
Exclude
Not a, b, c
03
Opposite
of [abc]
04
Filter
replace → ""
05
Expand
[^abc0-9]
06
^ first
After [ only
Fundamentals
Introduction
You already know that [abc] matches one letter from a small set. The negated form [^abc] inverts that rule: match anything except those three letters.
This is useful when a few characters are forbidden—blocking specific letters in usernames, stripping unwanted symbols from tokens, or validating that input does not contain particular characters.
Concept
Understanding the [^abc] Character Class
The caret ^ immediately after [ negates everything that follows inside the brackets until ]. For [^abc], any character other than lowercase a, b, or c is a match.
JavaScript
/[^abc]/.test("dog"); // true ("d" is allowed)
/[^abc]/.test("cab"); // false (only a, b, c present)
/[^abc]/.test("a1z"); // true ("1" and "z" match)
Digits, uppercase letters, spaces, and punctuation all match [^abc] because they are outside the excluded trio.
💡
Beginner Tip
To keep only a, b, and c, remove everything else: str.replace(/[^abc]/g, ""). That is the mirror image of using [^abc] to find what you want to delete.
Usage
How to Use [^abc] in JavaScript
Common workflows mirror other character classes—detect, extract, replace, and validate:
Use test() to check for forbidden characters, match() to list them, and replace(/[^abc]/g, "") to keep a sanitized subset.
Foundation
📝 Syntax
JavaScript
/[^abc]/ // one char not in {a,b,c}
/[^abc]+/ // one or more excluded chars in a row
/[^abc0-9]/ // not a,b,c and not a digit
str.replace(/[^abc]/g, "") // keep only a, b, c
Common patterns
/[^abc]/ — find any character outside the set.
/^[^abc]+$/ — entire string contains no a, b, or c.
/[abc]/ — positive counterpart (matches a, b, or c).
!/[^abc]/.test(s) — confirm string uses only a, b, c.
Cheat Sheet
⚡ Quick Reference
Goal
Pattern
One char not a/b/c
[^abc]
Keep only a, b, c
str.replace(/[^abc]/g, "")
No a, b, c anywhere
/^[^abc]*$/ or !/[abc]/.test(s)
List forbidden chars found
str.match(/[^abc]/g)
Exclude letters + digits
[^abc0-9]
Positive set
[abc]
Compare
📋 [^abc] vs [abc] vs [^0-9]
Three negated and positive classes with different exclusion rules.
Allow abc
[abc]
3 letters
Block abc
[^abc]
Everything else
Block digits
[^0-9]
Non-digits
Combined
[^abc0-9]
Letters+digits out
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it links. Examples cover detection, extraction, sanitizing, validation, and combined exclusions.
📚 Getting Started
Detect characters outside the a–b–c set.
Example 1 — Test for Characters Outside a, b, c
Return true when the string contains any letter or symbol not in the excluded set.
Checking for forbidden letters is often clearer with the positive class /[abc]/. The anchored negated form /^[^abc]+$/ requires every character to fall outside the banned set.
Example 5 — Exclude Letters and Digits with [^abc0-9]
Match only punctuation and symbols by negating both a custom letter set and digits.
For Unicode letter classes, consider modern \p{} properties when targeting international text.
Always use the g flag when removing all excluded characters with replace.
Compatibility
Browser & Runtime Support
Negated custom character classes like [^abc] are part of core JavaScript regular expression syntax.
✓ Baseline · ES3+
RegExp [^abc]
Supported in every browser and Node.js version. Combined exclusions such as [^abc0-9] use the same universal syntax.
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
[^abc]Excellent
Bottom line: Safe everywhere. Negated character classes behave consistently across all JavaScript runtimes.
Wrap Up
Conclusion
The [^abc] negated class completes the character-class toolkit alongside [abc], [0-9], and [^0-9]. It matches anything except the listed letters, making it perfect for filtering, validation, and cleanup.
Place ^ first inside brackets, combine exclusions when needed, and pair with replace to keep sanitized alphabets. Next, learn (x|y) alternation to match entire pattern alternatives.
Use replace(/[^abc]/g, "") to keep allowed letters
Add uppercase to the exclusion when case matters
Combine ranges for compact exclusions: [^abc0-9]
Prefer /[abc]/ when checking for forbidden letters
❌ Don’t
Confuse [^abc] with literal sequence (abc)
Assume uppercase is excluded without listing it
Forget g when stripping all outsiders
Place ^ away from the start unless you mean a literal caret
Overuse negated classes when a positive check reads clearer
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about RegExp [^abc]
Exclude specific letters from matches in JavaScript.
5
Core concepts
🚫01
Negate
[^abc]
Syntax
🔄02
vs [abc]
Opposite.
Compare
🛠03
Sanitize
replace g.
Pattern
➕04
Combine
[^abc0-9].
Expand
⚠05
Case
Add ABC.
Pitfall
❓ Frequently Asked Questions
[^abc] is a negated character class. The caret ^ right after [ inverts the set, so the pattern matches any single character that is NOT a, b, or c.
[abc] matches a, b, or c. [^abc] matches everything else—digits, other letters, spaces, and punctuation. They are opposites for those three characters.
No. Every character in "cab" is a, b, or c, so [^abc] finds no match in that string. test() returns false and match() returns null.
Yes. List them after ^: [^abcxyz] excludes six letters. You can mix ranges too: [^abc0-9] excludes a, b, c, and all digits.
Immediately after the opening bracket: [^abc]. If ^ appears elsewhere inside the class, it is usually a literal caret character.
Negated character classes are core regex syntax since ES3. [^abc] works in every browser and Node.js version.
Did you know?
Negated and positive classes are complements: anything that matches [^abc] does not match [abc] at the same position, and vice versa. Together they partition the set of possible single characters (for a given case and Unicode rules).