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 text

Matching text - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Matching text

- [Voiceover] The fundamental purpose of regular expressions is to match text. The match operator returns a logical value. And so, down here in line nine, you notice that the match operator is used in a logical test for the if statement. So that's the match operator right there, the equals sign and the tilde symbol. And so if this match succeeds, and there is a match, it'll say True. And if there is no match, it'll say False. So we see that in the regular expression there we have this string l i n e, line. And you'll see that it's also in the string that we're testing against, $s, which is listed here as the string in the match operator. And so if I run this, we should get True as our result, and we do. So this is a simple way to test a regular expression. Another common way to test a regular expression is by using a precompiled regular expression and using a ternary operator. So that would look something like this. My $re, so that's for the precompiled regular expression which we…

Contents