Need to match one character without spelling out every possibility? A character class puts the choices inside square brackets. `[abc]` matches one `a`, `b`, or `c`; `[a-m]` matches one character from `a` through `m`, inclusive. A class is one regex term, so `[a-m]+` matches a sequence of those characters. section 12.2.2 section 12.7
Three details prevent common mistakes:
- Put `^` immediately after `[` to exclude the listed characters: `[^abc]` matches one character other than `a`, `b`, or `c`. Outside a class, `^` can instead anchor a match to the start of the string. section 12.2.2
- A dash can specify an inclusive range. To include a literal dash alongside `a` through `m`, put it first: `[-a-m]`. section 12.2.2
- Shorthands can stand in for familiar sets: `\d` corresponds to `[0-9]`, and `\w` to `[A-Za-z0-9_]`. Their uppercase counterparts negate those sets. `\b` is different: it marks a word boundary, not a character to consume. section 12.2.2 section 12.4.3
Extract tokens while leaving separators out
`/([^\s,]+) of ([^\s,]+)/g` uses `[^\s,]` to match one character that is neither whitespace nor a comma. The `+` extends that choice into a sequence; parentheses capture each sequence. Used with `matchAll`, the pattern extracts names and clans from a comma-separated roster. The class alone does not match a whole name—the repetition operator does that work. section 12.4.2
Match a letter after a hyphen
`/-([a-z])/g` finds a hyphen followed by a lowercase letter. With `replace` and a function that uppercases the captured letter, it changes `shadow-clone-jutsu` to `shadowCloneJutsu`. Here the hyphen is outside the brackets, so it is a literal hyphen rather than range syntax. section 12.5
Choose a class for one character from a set, a negated class for one character outside it, and a repetition operator when the choice must continue. Add groups, boundaries, or flags when the surrounding pattern needs extraction, position checks, or different matching behavior. section 12.2.2 section 12.4.3 section 12.7









