Character Classes
In a pattern match, you may match any character that has—or that does not
have—a particular property. There are four ways to specify character
classes. You may specify a character class in the traditional way, using
square brackets and enumerating the possible characters, or you may use
any of three mnemonic shortcuts: classic Perl classes like \w, using properties like \p{word}, or using legacy POSIX classes like
[:word:]. Each of these shortcuts
matches only one character from its set. Quantify them to match larger
expanses, such as \d+ to match one or
more digits. (An easy mistake is to think that \w matches a word. Use \w+ to match a word — provided by “word” you
mean a programming language identifier with underscores and digits and
such, not an English-language word.)
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