in reply to get first e.g. 5 words and replace the remaining string with ... with one regex
You probably want to do something like:
my $a = qq(foo bar foo bar foo bar foo bar foo bar); $a =~ s/((\w+\s+){4}).+/$1.../g; print $a; __END__ output: foo bar foo bar ...
This way, any words past the fourth are replaced by "...", and if there are fewer than four words no replacement happens.
|
|---|