Trying to wrap the last 3 words in a tag
$str = \'Lorem ipsum dolor sit amet\'; $h2 = preg_replace(\'/^(?:\\w+\\s\\w+)(\\s\\w+)+/\', \'
Here it is:
$h2 = preg_replace('/(\w+\s\w+\s\w+)$/', '$1', $str);
Since its last three words, so make the left side(from begin) as open to have the match.