[VPM] regex found matches array

Darren Duncan darren at darrenduncan.net
Fri Feb 27 18:45:17 PST 2009


Jer A wrote:
> How do i retrieve the "groups" array, from the regex query that contains 
> the groups in $1 $2 $3 ...etc . the script has no hardcoded knowledge of 
> the regex pattern, as it is read from a string into a $var, which is 
> evaluated like this /$var/eg.
> 
> Thanks in advance for all help....I hope you can understand, as I find 
> it hard to explain.

Say something like this:

   my $results = [$source =~ m/$pattern/g];

Then the $results array has one element per capture by the pattern.

Make sure the whole pattern-match expression is in list context (such as my 
array value constructor provides) or otherwise it will just (in scalar context) 
return the count of matches.

-- Darren Duncan


More information about the Victoria-pm mailing list