QUANTIFIERS

Counted repetition

{n} exactly n times. {n,m} between n and m. {n,} at least n.

\d{4} exactly four digits. Matches "2024", not "999" or "12".
\d{2,4} two to four digits. In "12345" it grabs the first four, "1234".
\d{2,} two or more digits, no upper limit. Matches "12" and "1200".

Braces are the precise quantifier. The others are shorthands for it: + is {1,}, * is {0,}, ? is {0,1}.

Careful: \d{4} finds four digits ANYWHERE, so inside "12345" it matches "1234". Pinning matches to whole words needs boundaries - next section.

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

Match every run of exactly four digits.

/ /
in 1999 and 2024
must match: "1999" "2024"
id 12345
must match: "1234"
room 42
must match nothing
DRILL 2/2- Zip codes

Match every run of exactly five digits.

/ /
zip 90210 and 00501
must match: "90210" "00501"
short 1234
must match nothing
phone 5551234
must match: "55512"