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.

Getting a list of matches

Getting a list of matches - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Getting a list of matches

- Sometimes you need more than just a fixed number of matches from a regular expression. In this lesson, I'll show you how to get a list of matches. Let's say I want to know what letters come after the letter "i" in my string. So, if I look at my string I see I have I-S, I-S, and I-N, so I want to get a list of those letters after the i, so, again, the list would consist of a "s", another "s", and an "n". So, instead of this here I'm going to create an array from a regular expression. So my regular expression says whatever comes after the "i", and I've got that in parentheses, and I have the /g which means to search globally throughout the string, not to stop after the first match. And it'll return those results as a list and put them into the array. So I'm going to say "foreach" my array and we'll go ahead and run it. And there's my "s", another "s", and an "n", and so it's that "s", and that "s", and that "n". So this uses the match operator on a list context, and the parentheses…

Contents