in reply to regexp find last word

Reverse the string and replace the first:
$_ = "fox comes and fox goes into forest"; $_ = reverse; s/xof/xof eht/; $_ = reverse; print;
Boris

Replies are listed 'Best First'.
Re^2: regexp find last word
by Anonymous Monk on Mar 02, 2005 at 14:54 UTC
    That just puts 'the' in front of the last fox, without considering the forest at all. It doesn't put 'the' in front of the last fox before a forest, except when that also happens to be the last fox on the line. That is, it will turn
    fox comes and fox goes into the forest. No fox left
    into
    fox comes and fox goes into the forest. No the fox left

      What, you mean he didn't see the forrest for the thes?

      Thats right, I was just to lazy to reverse forest.* as well. But the idea is to reverse the string and replace the first.
      Boris