我需要替换不是单号,单引号,逗号,句号,问号或感叹号的所有内容。但我的正则表达式似乎并没有正常工作。我究竟做错了什么?替换不是字母,单引号,逗号,句号,问号或感叹号的所有内容
$userResponse = "i'm so happy that you're here with me! :)";
$userResponse = preg_replace("~(?!['\,\.\?\!a-zA-Z]+)~", "", $userResponse);
echo $userResponse;
结果:
i'm so happy that you're here with me! :)
需要结果:
i'm so happy that you're here with me!
在结尾添加一个加号]会使它更快一点吧? – frosty
是的,你是对的。我会更新它 – JanLeeYu