in reply to get first e.g. 5 words and replace the remaining string with ... with one regex

How's this:
#!/usr/local/bin/perl -w use strict; my $text="Twenty centuries of stony sleep were vexed to nightmare"; my $numwords=5; my $replacement="lead to a crick in the back."; print $text; $text=~ s/^((\w+\s){$numwords}).*$/$1.$replacement/e; print $text; __END__ Twenty centuries of stony sleep were vexed to nightmare Twenty centuries of stony sleep lead to a crick in the back.
perlre is your friend.

CU
Robartes-

  • Comment on Re: get first e.g. 5 words and replace the remaining string with ... with one regex
  • Download Code