我需要替換不是單號,單引號,逗號,句號,問號或感嘆號的所有內容。但我的正則表達式似乎並沒有正常工作。我究竟做錯了什麼?替換不是字母,單引號,逗號,句號,問號或感嘆號的所有內容
$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