From the course: Perl 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Matching classes of characters

Matching classes of characters - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Matching classes of characters

- [Voiceover] Regular expressions include the ability to match a class of characters like any alphabetic character or any of the digits four, seven, or nine. For example, if I wanna match a whitespace character, I can use this. So the backslash followed by the lowercase s will match anything that is whitespace. This includes spaces, tabs, new lines, form feeds, and vertical tabs. The capital S matches anything that is not whitespace, and there's a pattern here. In a lot of these classes, the capital version is negated. So it's anything that is not. So this is useful for finding words. For example here, I'm just gonna change this around a little bit to say "my @a", so I'm making an array called "a", equals, and I'm putting a slash g here so that it gives us all the matches from a line and take that out and instead, say "foreach @a". So when I run this, getting anything that is not whitespace. So it's basically giving me a list of all of the individual letters in the string. And if I…

Contents