in reply to Needing to take out 3rd word of sting

First of all, what do you consider a word? Is "isn't" a word, or is it two? What about words with hyphens?

Second, what exactly do you mean by "putting it back"? If you first take it out, then put it back, you have back the original thing, don't you? Or do you put it back elsewhere?

Third, what submit button are we talking about? Perl doesn't have any submit button, so, what do you mean?

Having said that, assuming you consider a word to be a sequence of \w chars, and any maximized sequence to be a word, this will remove the third word from a string:

$str =~ /(\w+\W+\w+\W+)\w+/$1/

Abigail

Replies are listed 'Best First'.
Re: Re: Needing to take out 3rd word of sting
by seaver (Pilgrim) on Sep 24, 2003 at 19:50 UTC
    Dont mean to be picky, fantastic solution, just that you forgot the 's' for substitution:

    $str =~ s/(\w+\W+\w+\W+)\w+/$1/;
    Sam