Step: Quantifiers: how many

Quantifiers: how many

Quantifiers repeat the preceding token: * = zero or more, + = one or more, ? = zero or one.

Why it matters: without quantifiers a pattern matches a fixed length; with them it matches runs of any size.

Example: ab+ means an a followed by one or more bs, so it matches "ab" and "abbb".

Your turn: match "ab" and "abbb" with ab+.

Pitfall: + and * are greedy — they grab as much as possible. You will tame that with lazy quantifiers (+?) later.

Input:
aaa ab abbb a
Expected:
[
  "ab",
  "abbb"
]
Step 5 of 11