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
In all the aforementioned cases, m can be a single character or a group of characters. We will discuss grouping in more detail later.

Get Java 9 Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.