Module lessons (3/4)
Negation: `[^...]`
A negated class matches anything except the listed characters.
What you'll learn in this lesson
- Reverse any character class by prefixing
^as the first character inside the squares ([^...]). - Replace risky wildcard matches (
".+?") with fast, backtracking-free negated classes ("([^"]+)"). - Distinguish class negation (
[^a]inside[...]) from string start anchor (^aoutside[...]).
Overview
Placing a caret ^ as the first character inside the square brackets reverses the meaning of the class: [^aeiou] consumes exactly any character as long as it is not any of those listed.
While [...] functions as a whitelist ("accept only these"), [^...] functions as a blacklist ("accept everything except these"). It is a key technique for stopping a match in front of a delimiter (quote, comma, slash) without generating excessive backtracking.
Sections covered in this lesson
- 1Mental model: the exclusion list
- 24 progressive examples step by step
- 3Guided practical exercises
- 4Quick check
Unlock "Negation: `[^...]`" and the full Regex Course curriculum
A negated class matches anything except the listed characters.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Regex Course plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.