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 - Perl Tutorial
From the course: Perl 5 Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
(Locked)
About regular expressions4m 8s
-
(Locked)
Matching text2m 9s
-
(Locked)
Common modifiers4m 58s
-
(Locked)
Extracting matches2m 5s
-
(Locked)
Getting a list of matches1m 46s
-
(Locked)
Simple matches2m 46s
-
(Locked)
Matching wildcards4m 38s
-
(Locked)
Matching classes of characters4m 23s
-
(Locked)
Matching metacharacters1m 37s
-
(Locked)
Search and replace4m 32s
-
(Locked)
Splitting strings2m 18s
-
(Locked)
-
-
-
-
-
-
-