That looks for a word followed by a space, repeated any number of times, followed by the word nice (with word boundaries around it) followed by a minimal number of characters before a final period. It replaces the first bit with 'A' and keeps the second around. /g, of course, makes it look for all the matches in the string.my $sentence = "This is a nice weather. He is a nice guy. We have some nice food in our dinner."; $sentence =~ s:(\w+\s)+(\bnice\b.*?\.):A $2:g; print "$sentence\n";
In reply to (chromatic) Re: How to substitute all the words before a certain word in the middle of a line?
by chromatic
in thread How to substitute all the words before a certain word in the middle of a line?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |