in reply to regexp find last word

Hi Try this,

$a = "fox comes and fox goes into forest"; $a =~ s#(fox.*?)(fox.*?forest)#$1the $2#gsi; print $a;

Replies are listed 'Best First'.
Re^2: regexp find last word
by Anonymous Monk on Mar 02, 2005 at 15:34 UTC
    Considering the regex doesn't contain 'forest', how on earth would it find the last fox before the forest? Your regex just puts 'the' in front of the second fox in the sentence. Which may work in the example, but doesn't solve the problem as stated.