Negated Sets [^abc]
Sometimes it's easier to specify what you DON'T want to match. Negated sets do exactly that.
The Caret Inside Brackets
[^abc] matches any character that is NOT a, b, or c.
Notice everything EXCEPT vowels is matched - consonants, spaces, and capitals.
Important: Position Matters
The ^ only means "not" when it's the first character inside brackets:
[^abc]= NOT a, b, or c[a^bc]= a, ^, b, or c (^ is literal here)
Exercises
Finding Non-Alphanumeric
Practical Example: Clean Text
Combining with Patterns
Excluding Specific Characters
Practice Playground
Try:
[^0-9]- everything except digits[^a-zA-Z]- everything except letters[^()]- everything except parentheses
Common Use Cases
| Pattern | Matches |
|---|---|
[^0-9] | Non-digits |
[^a-zA-Z] | Non-letters |
[^a-zA-Z0-9] | Non-alphanumeric |
[^\s] | Non-whitespace |
[^"] | Anything except quotes |
Key Takeaways
[^...]matches any character NOT in the set- The
^must be first inside the brackets - Useful for "everything except" patterns
- Remember to include/exclude spaces as needed

