A Few More Patterns

To finish up—because we have a little space left over today—I'd like to tuck a couple more patterns into your regular expressions repertoire, so that you can keep building on what you've learned (and so that I can use them in the last example you're about to work through).

So far you've learned about patterns with individual characters:

/abc/

Patterns with digits:

/\d/

And patterns with nondigits:

/\D/

Here's another one: \s is a whitespace character. Whitespace in Perl is a space, a tab, a newline, a carriage return, or a formfeed. The \s pattern counts as any of these. Just as with \d, however, \s only means a single whitespace character, so the pattern /\s/ will match one and only one space, tab, newline, and so on. ...

Get Sams Teach Yourself Perl in 21 Days, Second 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.