preg_replace('/s(w+)$/i', ' $1', 'this is a sample sentence');
I’ve got most of this: /s(w+)$/i
s (Match a space character)
w (match an alpha numeric character) + (keep matching this until fail. Aka the space)
$ (the matched characters should end with (w+)
So it matches a space character followed by (and ending with) a string of alpha numeric characters. I’m not exactly sure what the i means, but I’m sure it must have something to do with the fact that it has matched the very last possible match.
$1 replaces the matched characters in the brackets with a non-breaking-space followed by the matched characters.