in reply to Re: regex capturing problem
in thread regex capturing problem

Doesn't really explain why I get only the last two parts as my regex started whith '^' and therefore can't just start matching in the middle of the string...

But the correct answer has already been given (thanks, erikharrison). I just wasn't aware that ()+ gives you just one item, no matter how often it matched.

pike

Replies are listed 'Best First'.
Re: Re: Re: regex capturing problem
by larryk (Friar) on Mar 21, 2002 at 16:23 UTC
    The point is not whether it can start matching in the middle of the string but whether it can start _capturing_ in the middle of the string. By adding a + to the first part you allow the RE engine to effectively ignore the ^ anchor while still forcing it to make a match at the end of the string.
       larryk                                          
    perl -le "s,,reverse killer,e,y,rifle,lycra,,print"
    
Re: Re: Re: regex capturing problem
by petral (Curate) on Mar 21, 2002 at 21:11 UTC
    Actually, it matches all of them, but since it is repeating, it overwrites the first match:
    $ perl -lwe"q<d'aujourd'hui> =~ /^((\w+')(?{print$+}))+([\w-]+)$/" d' aujourd' $
        p