The [abc] character class matches exactly one character from a list you choose—in this case a, b, or c. It is the building block for custom letter sets, category codes, and flexible pattern matching beyond simple ranges like [0-9].
01
Class
[abc]
02
One of
a, b, or c
03
Order
Doesn’t matter
04
Quantifiers
+, {n}
05
Case
Sensitive
06
Not (abc)
Class vs group
Fundamentals
Introduction
Character classes let you match one character from a defined set. While [0-9] covers all digits with a range, [abc] lists specific characters explicitly. The engine picks whichever single letter appears at the current position.
Use this pattern when only a handful of letters are valid—quiz answers, hex digits without full ranges, product codes, or filtering text that must use a limited alphabet.
Concept
What Is the [abc] Character Class?
Square brackets create a character class. Each character listed inside is an alternative: the pattern matches if the next input character equals any one of them.
JavaScript
/[abc]/.test("dog"); // false (no a, b, or c)
/[abc]/.test("cab"); // true (matches "c")
/[abc]/.test("A"); // false (uppercase A is different)
[abc], [bac], and [cab] are equivalent—order inside brackets does not change meaning. This is different from parentheses (abc), which match the literal three-letter sequence in order.
💡
Beginner Tip
Think of [abc] as “pick one letter from this menu.” To match a whole word built only from those letters, add + and anchors: /^[abc]+$/.
Usage
How to Use [abc] in JavaScript
Combine the class with RegExp methods the same way you would [0-9] or any other pattern:
test() returns true as soon as it finds any character equal to a, b, or c anywhere in the string.
📈 Practical Patterns
Extract, validate, and filter using the custom set.
Example 2 — Find All Matching Letters with match()
Collect every a, b, or c in a longer word.
JavaScript
const word = "alphabet";
const first = word.match(/[abc]/);
console.log(first[0]); // "a"
const all = word.match(/[abc]/g);
console.log(all); // ["a", "b", "a"]
[abc]+ repeats the class so each position must be a, b, or c. The plus requires at least one character; combine with anchors to validate the full token.
Example 5 — Keep Only a, b, and c with replace()
Strip digits and symbols, leaving only characters from your allowed alphabet.
[^abc] matches anything not in the set. Removing those characters leaves a clean string. Wrapping matches with [$&] highlights allowed letters in place.
Applications
🚀 Common Use Cases
Multiple-choice validation — accept only a, b, or c answers.
Custom alphabets — restrict input to a small allowed character set.
Text filtering — extract or highlight specific letters from mixed content.
Game logic — validate moves or tokens drawn from a limited letter pool.
Parsing codes — match status flags represented by single letters.
Building larger classes — combine sets: [abc0-9] for letters plus digits.
Watch Out
Important Considerations
One character per token — bare [abc] matches a single position; use + for sequences.
Case sensitivity — [abc] excludes uppercase unless you add ABC or the i flag.
Not a literal word — [abc] matches "cab" one letter at a time; it is not the same as matching the word "abc" in order unless quantifiers align.
Special characters — inside [ ], most characters are literal; place - at the start/end to match a hyphen literally.
Metacharacters — ], \, and ^ (at the start) need careful placement or escaping inside classes.
🧠 How [abc] Matches Text
1
Define the set
Characters inside [ ] form an allowed list. Here: a, b, c.
Pattern
2
Read next char
The engine checks whether the current input character is in the set.
Compare
3
Repeat if +
With a quantifier, the engine keeps matching allowed letters consecutively.
Quantify
4
📝
Match or fail
In the set → success. Not in the set → no match at this position.
Important
📝 Notes
Combine with digits: [abc0-9] matches one letter a–c or one digit.
Negate the set: [^abc] matches any character except a, b, and c.
For all lowercase letters, prefer [a-z] over listing 26 characters.
Use explicit sets when the allowed pool is small and non-contiguous.
See [0-9] for digit ranges and [^0-9] for negated classes.
Inside classes, . is usually a literal dot, not “any character.”
Compatibility
Browser & Runtime Support
The [abc] character class uses core JavaScript regular expression syntax supported everywhere.
✓ Baseline · ES3+
RegExp [abc]
Supported in every browser and Node.js version. No polyfill required.
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. Custom character classes work identically across all JavaScript runtimes.
Wrap Up
Conclusion
The [abc] character class is a simple, powerful way to match one character from a hand-picked set. It extends the same bracket syntax you learned with [0-9] to arbitrary letters and symbols.
Use it for validation, filtering, and extraction when only specific characters are allowed. Remember the difference from (abc), add quantifiers for longer tokens, and normalize case when uppercase matters.
Over-list characters when a range would be clearer
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about RegExp [abc]
Custom character sets in JavaScript regex.
5
Core concepts
📝01
Set
[abc]
Syntax
🔢02
One of
a, b, or c.
Meaning
🔄03
Order free
[cab] OK.
Rule
➕04
+ repeat
Long tokens.
Pattern
⚠05
Not (abc)
Class vs group.
Pitfall
❓ Frequently Asked Questions
[abc] is a character class that matches exactly one character—either a, b, or c. The order inside the brackets does not matter: [abc] is the same as [cab] or [bac].
Not by itself. Each [abc] token matches one character. The string "abc" matches when you use [abc] three times or [abc]+ to match one or more letters from the set in a row.
Yes. [abc] matches lowercase a, b, and c only. To include uppercase, list them explicitly: [abcABC] or use the i flag with a pattern that accounts for both cases.
[abc] is a character class matching one letter from the set. (abc) is a capturing group matching the literal sequence "abc" in that exact order.
[abc] matches only three specific letters. [a-z] matches any single lowercase letter from a through z—a much wider set.
Character classes are core regex syntax since ES3. [abc] works in every browser and Node.js version.
Did you know?
You can merge a custom set with a range in one class: [abc0-9] matches a single character that is either a, b, c, or any digit. This keeps patterns compact when input draws from multiple small pools.