PHP正则表达式删除除句点之外的非字母数字

jim*_*ith 1 php regex

我很难找到解决方案。如何避免丢失此正则表达式中的句点?

$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
Run Code Online (Sandbox Code Playgroud)

cee*_*yoz 5

$text = preg_replace('@[^0-9a-z\.]+@i', '-', $text);
Run Code Online (Sandbox Code Playgroud)

这会以不区分大小写的方式替换 0-9、az 或句点以外的任何内容。

  • 不需要逃避这个点,尽管我想这并没有什么坏处。 (3认同)