in reply to Getting + and * to generate multiple captures

Hi jgeisler,

Have you tried split?

use strict; use warnings; my $msg = "the quick brown fox jumps over the lazy dog"; my $text = "fox"; my @words = ( ); if ($msg =~ /$text \s (((\w+) \s?)+)/x) { @words = split(/\s+/, $1); # @words now contains the list you want... printf "Words: %s\n", join(',', @words); } __END__ [Results] Words: jumps,over,the,lazy,dog

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: Getting + and * to generate multiple captures
by jgeisler (Initiate) on Aug 17, 2006 at 18:00 UTC
    I've simplified my problem somewhat to ask the initial question. split() would cause me much pain because I really have multiple regular expressions with quite different separators (not the simple \s used in the example code). However, since all the regular expressions could capture the same content, I would like to only use one piece of code after the appropriate regular expression matches and returns the relevant information. In other words, I'm doing something like:
    foreach my $rx (@rxs) { if (my @captures = $text =~ /$rx/) { # do something meaningful with the captures } }
    I'd have to have a separate part to split() apart each value negating much of the gain of the loop.