in reply to regex: list each ocurrence of a pattern in a line
Meet the "g" modifier.
Or evenmy @matches; for (@fields) { push @matches, /%%(\w+?)%%/g; }
my @matches = map /%%(\w+?)%%/g, @fields;
The "?" quantifier isn't necessary. I don't know if it's faster with or without it. If probably only matters if the elements of @fields are very long strings, so you might as well leave it out.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex: list each ocurrence of a pattern in a line
by spatterson (Pilgrim) on Nov 19, 2008 at 12:05 UTC |