Like PHP strip punctuation, but I want to keep the apostrophe. Example:
I'm a student, but I don't like the school. I'll quit school.
The string after strip should be:
I'm a student but I don't like the school I'll quit school
How can I do that with regular expression or other ways?
If you want to support all Unicode punctuation characters as well then use this regex:
$str = preg_replace("#((?!')\pP)+#", '', $str);
This regex is matching Unicode punctuation character class \pP and match will avoid apostrophe character using negative lookahead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With