php regex: how to match number + letters + Chinese

one text

Solution:

You need

preg_replace('~[^0-9a-zA-Z\p{Han}]+~u', '', $raw)

See the regex demo.

The [^0-9a-zA-Z\p{Han}]+ is a negated character class that matches any one or more chars other than ASCII digits, ASCII letters and any Chinese chars.

It is important to use the u flag with this pattern, as your input is Unicode strings.

See the PHP demo:

$raw = 'a>b%%c##1@23测$$试??\\:.##,,??!!';
echo preg_replace('~[^0-9a-zA-Z\p{Han}]+~u', '', $raw);
// => abc123测试

Source