in reply to Re: Getting + and * to generate multiple captures
in thread Getting + and * to generate multiple captures

Thanks, that will do what I want. I'm assuming I need to access @matches explicitly after running the match to grab the values I care about? Can I do something like:
/ $text (?: \s (\w+) (?{ push @matches, $^N }) )+ /x;
to just populate @matches instead of creating the stack and then flattening it?

Replies are listed 'Best First'.
Re^3: Getting + and * to generate multiple captures
by ikegami (Patriarch) on Aug 17, 2006 at 19:53 UTC

    For that very specific regexp, yes. That's the simplification to which I alluded. I'll repeat the reason I didn't post the simplification

    It's much safer to assume there's always the possibility of backtracking through any (?{...}). That's why $^R is used.

    It's too easy to miss a case where backtracking can occur.

    For example,
    / $text (?: \s (\w+) (?{ push @matches, $^N }) ){2,} / is wrong.
    / $text (?: \s (\w+) (?{ push @matches, $^N }) )+ ... / is wrong.
    / $text (?: \s (\w+) (?{ push @matches, $^N }) ... )+ / is wrong.