Java - Regular Expressions Quantifiers


You can set the number of times a character may match the sequence of characters.

To match all two digit integers, your regular expression would be \d\d, which is the same as [0-9][0-9].

Quantifiers express a pattern like "one digit or more".

Quantifiers and their meanings are listed in the following table.

Quantifiers Meaning
*Zero or more times
+One or more times
?Once or not at all
{m} Exactly m times
{m, }At least m times
{m, n} At least m, but not more than n times


Quantifiers must follow a character or character class.

For example, \d+ says that match one or more number of digits.