We briefly looked at quantifiers in the first chapter. Quantifiers allow us to quantify the occurrences of our matches. We can match the input in various ways, such as an optional match, an open-ended range, a closed range, and by using a fixed number. Let's take a closer look at them, as quantifiers are integral to most of the regular expressions.
Quantifiers
Basic quantifiers
The following table lists all the quantifiers available in Java regular expressions:
Quantifier | Meaning |
m* | Match m zero or more times |
m+ | Match m one or more times |
m? | Match m one or zero times (also called an optional match) |
m{X} | Match m exactly X times |
m{X,} | Match m X or more times |
m{X,Y} | Match m at least X and at most Y times |