preg_replace 含 () 个字符

preg_replace with () characters

我想使用 preg_replace 来清理一个字符串,但我想继续使用这个字符 () - 括号

我正在使用此代码

$string = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $string);
$string = preg_replace('/[^\p{Latin}\d ]/u', '', $string);

我想删除除括号字母和数字以外的所有内容

如果我理解正确,请使用:

/[^\p{Latin}0-9()]/u

这将匹配除括号、字母或数字以外的任何内容。

所以完整代码:

$string = preg_replace('/[^\p{Latin}0-9()]/u', '', $string);