Quantifiers
A quantifier specifies how many times (or if) something
occurs. There are three quantifier characters and a syntax for
specifying quantities more explicitly. For example, (a|b)?c matches ac, bc, and
c, because the question mark
indicates zero or one instances of a pattern. Here are all the
quantifiers and their syntax:
?Zero or one of a pattern.
*Zero or more of a pattern.
+One or more of a pattern.
{x}The pattern must occur exactly
xtimes. The pattern(a|b){3}matchesaaaandabb, but notab.{x,}The pattern must occur at least
xtimes. The pattern(a|b){3,}matchesaaaandaaaaaaaaa, but notaa.{x,y}The pattern must occur at least
xtimes, but no more thanytimes. The pattern(a|b){2,5}matchesaaandaaa, but notaaaaaa.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access