Skip to Main Content
Sams Teach Yourself Perl in 21 Days, Second Edition
book

Sams Teach Yourself Perl in 21 Days, Second Edition

by Laura Lemay, Rafe Colburn
May 2002
Beginner content levelBeginner
704 pages
16h 37m
English
Sams
Content preview from Sams Teach Yourself Perl in 21 Days, Second Edition

Matching Groups of Characters

So far, so good? The regular expressions we've been building so far shouldn't strike you as being that complex, particularly if you look at each pattern in the way Perl does, character by character and alternate by alternate, taking grouping into effect. Now we're going to start looking at some of the shortcuts that regular expressions provide for describing and grouping various kinds of characters.

Character Classes

Say you had a string, and you wanted to match one of five words in that string: pet, get, met, set, and bet. You could do this:

/pet|get|met|set|bet/

That would work. Perl would search through the whole string for pet, then search through the whole string for get, then do the same thing for met, and ...

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.
Start your free trial

You might also like

Sams Teach Yourself Perl in 24 Hours

Sams Teach Yourself Perl in 24 Hours

Clinton Pierce
Perl Debugged

Perl Debugged

Peter Scott, Ed Wright

Publisher Resources

ISBN: 0672320355Purchase book