perlre is your friend.#!/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.
CU
Robartes-
In reply to Re: get first e.g. 5 words and replace the remaining string with ... with one regex
by robartes
in thread get first e.g. 5 words and replace the remaining string with ... with one regex
by dreamy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |