in reply to Getting + and * to generate multiple captures

Hi jgeisler

See, you have used '+' which matches the unknown number of words exactly. But if you want to capture the matched unknown words after text, you have to use another parantheses as shown below.

use strict; use warnings; my $text = 'text'; my $str = 'text some words here'; if ($str =~ /$text \s ((?: (\w+) \s?)+)/x) { print "The words after text are :$1\n"; } prints: The words after text are :some words here

Prasad

Replies are listed 'Best First'.
Re^2: Getting + and * to generate multiple captures
by jgeisler (Initiate) on Aug 17, 2006 at 17:48 UTC
    The problem with this is that I want each word in a separate array element. I'd have to use split() on this outer-capture and it turns out that this is not ideal for my bigger problem.