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 x times. The pattern (a|b){3} matches aaa and abb, but not ab.

{x,}

The pattern must occur at least x times. The pattern (a|b){3,} matches aaa and aaaaaaaaa, but not aa.

{x,y}

The pattern must occur at least x times, but no more than y times. The pattern (a|b){2,5} matches aa and aaa, but not aaaaaa.

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.