in reply to Re: Question on File position, pulling words
in thread Question on File position, pulling words

Almost correct, you need to anchor the regex at the end of the string.

my @last_two = $string =~ /(\S+)\s+(\S+)$/;

Replies are listed 'Best First'.
Re^3: Question on File position, pulling words
by Narveson (Chaplain) on Mar 04, 2008 at 07:11 UTC

    Don't overlook my .*. As you can learn in perlretut,

    the first quantifier .* grabs as much of the string as possible while still having the regexp match.

    My submission said

    /.* # Read as far as possible before \s # matching whitespace, (\S+) # capturing a word, \s+ # matching more whitespace, (\S+) # and finally capturing the last word. /x

      True and faster, at least on long strings (I had hoped to riposté by pointing out mine was faster but that is true only on short strings ;-)