Step: Ranges and negation

Ranges and negation

Inside a class you can use a range with - (e.g. [a-z], [A-Z], [0-9]), and you can negate the whole class with a leading ^ ([^0-9] = "anything but a digit").

Why it matters: ranges express "any letter" or "any digit" without listing every character.

Example: [0-9] matches each digit; [^0-9] matches each non-digit.

Your turn: match every digit with [0-9].

Pitfall: a - is only a range when it sits between two characters — at the start or end of a class ([-a]) it is a literal hyphen.

Input:
R2-D2 & C-3PO
Expected:
[
  "2",
  "2",
  "3"
]
Step 4 of 11