O'Reilly logo

Sams Teach Yourself Perl in 21 Days, Second Edition by Rafe Colburn, Laura Lemay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Matching Multiple Instances of Characters

Ready for more? The second group of regular expression syntax to explore is quantifiers. The patterns you've seen up to now refer to individual things or groups of individual things, but quantifiers enable you to indicate multiple instances of things—or potentially no things. These regular expression metacharacters are called quantifiers because they indicate some quantity of characters or groups of characters in the pattern you're looking for.

Perl's regular expressions include three quantifier metacharacters: ?, *, and +. Each refers to some multiple of the character or group that appears just before it in the pattern.

Optional Characters with ?

Let's start with ?, which matches a sequence that may ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required