6Quantifiers * + ?
Repeat the previous token: * zero or more, + one or more, ? optional.
A quantifier says how many times the token in front of it may repeat:
| Quantifier | Meaning | Example |
|---|---|---|
* | zero or more | go*gle: ggle, gogle, google… |
+ | one or more | \d+: 7, 42, 2026 |
? | zero or one (optional) | colou?r: color, colour |
A quantifier applies only to the one token right before it. ab+ means a, then one or more b. To repeat several characters, group them – that is coming soon.
Exercises
Lesson complete – well done!