in reply to How to substitute all the words before a certain word in the middle of a line?

s/\b\w+\s+nice\b/A nice/g;
or
$w = 'nice'; $r = 'A'; s/\b\w+(\s+$w)\b/$r$1/g;
should work

Replies are listed 'Best First'.
RE: Re: How to substitute all the words before a certain word in the middle of a line?
by le (Friar) on Jul 12, 2000 at 11:19 UTC
    The first one does not work, at least not here, when I supply the given sentence.
    You just replace the last word before 'nice' with 'A'.
      More careful reading will help in my case :)
      The word "all" was lost by me :)