CHARACTER CLASSES

Negated sets

A leading caret flips a set to match anything you did not list.

Put a caret right after the opening bracket and the set flips. [^aeiou] matches any single character that is NOT one of a, e, i, o, u. In "cat" it matches c and t and skips the a. The caret means "anything except these".

Everything else about sets carries over: it still consumes exactly one character. [^0-9] matches one non-digit, so in "a1b2" it matches a and b and skips the digits.

Negated sets are the workhorse of real-world regex. "Everything up to the next quote" is [^"], repeated once you can say "repeated" - the quantifiers section adds that, and [^"] turns out to be the precise alternative to a lazy quantifier in greedy vs lazy.

The caret negates only as the FIRST character in the set. Anywhere else it is a plain character: [a^] matches a or a literal caret.

PRACTICE - 2 DRILLS 0/2 DONE
DRILL 1/2

Match every character that is not a digit.

/ /
a1b2
must match: "a" "b"
x9y
must match: "x" "y"
123
must match nothing
DRILL 2/2- Not a vowel

Match every character that is not a lowercase vowel.

/ /
sky
must match: "s" "k" "y"
rhythm
must match: "r" "h" "y" "t" "h" "m"
aeiou
must match nothing