in reply to Re: Regex triggering uninitialised values
in thread Regex triggering uninitialised values

Thanks, ikegami!

How will the regex change if I need to match more than one digit before %var%? Just can't think of anything at the moment...

Edited: Sorry, just discovered that moving the ? solves the problem.

#$str =~ s/(\d+?)%var%(.*)/$1REPLACED$2/;</strikeout> As pointed out by Eimi Metamorphoumai $str =~ s/(\d*)%var%(.*)/$1REPLACED$2/;</strikeout>

Replies are listed 'Best First'.
Re^3: Regex triggering uninitialised values
by Eimi Metamorphoumai (Deacon) on Nov 19, 2004 at 18:01 UTC
    Watch out! '+?' isn't the same as '*' in a regexp. If you want zero or more, you want '*'. '+?' will only match if there is one or more, but will match non-greedily (that is, as few characters as possible).
      Ah, thanks!