Match all occurrences?

my @matches = ($result =~ m/INFO\n(.*?)\n/);

So, in Perl, I want to keep all matches to this regular expression. I want to keep the value between INFO \ n and \ n every time this happens.

But I get only the last fill. Is my regex wrong?

+5
source share
1 answer

Use the modifier /gfor global matching.

my @matches = ($result =~ m/INFO\n(.*?)\n/g);

Len quantification in this case is not needed, because it .does not correspond to new lines. The following will give better performance:

my @matches = ($result =~ m/INFO\n(.*)\n/g);

/scan be used if you want periods to match newlines. See perlre for more on these modifiers .

+10
source

All Articles