If you want to also support all Unicode punctuation characters, use this regex:
$str = preg_replace("#((?!')\pP)+#", '', $str);
This regular expression matches the character character of the Unicode prefix character \pP, and matching will escape the apostrophe character using a negative result.
source
share