Is it possible to store all matches for a regular expression into an array?
I know I can use ($1,...,$n) = m/expr/g;, but it seems as though that can only be used if you know the number of matches you are looking for. I have tried my @array = m/expr/g;, but that doesn’t seem to work.
If you’re doing a global match (
/g) then the regex in list context will return all of the captured matches. Simply do:This command for example:
Gives the output: