$
means "the end of the line", so /.* ([^ ]+ [^ ]+)$/
means match everything (.*) until one or more non-space characters ([^ ]+) which are followed by a space and then another set of one or more non-space characters, until the end of the line. That allows you to find the last two words of the line.