Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

419
Visualizações
php regex: how to match number + letters + Chinese

I am trying to handle the string which got letters, numbers, Chinese and some punctuations and left number, letters and Chinese only like below

raw string

a>b%%c##1@23测$$试??\\:.##,,??!!

result

abc123测试

for Chinese, preg_replace('/\P{Han}+/u', '', $text) works perfectly

测试 // result

and for number and letters, preg_replace('/[^0-9a-zA-Z]/', '', $text) works too.

abc123 // result

But how can I combine them?

why preg_replace('/[\P{Han}]|[0-9a-zA-Z]/u', '', $raw); doesn't work as expected?

Thanks a lot for anyone help!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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测试
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda