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

334
Visualizações
Removing Special Character in JavaScript

string = string.replace(/[^a-zA-Z0-9]/g, '');

Can anyone Explain this snippet (/[^a-zA-Z0-9]/g, '') ??? What it means? I know what it does. But how

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

0

The snippet

string = string.replace(/[^a-zA-Z0-9]/g, '');

Uses RegEx (Regular Expression) to find a paten and then replace it.

This is how it works:

  1. The .replace function replaces a specific character or patern in a string (first argument) with another (second argument)
  2. The /[^a-zA-Z0-9]/g is the regex. a-z means lower case characters from a-z, A-Z means upper case characters from a-z and 0-9 means number characters from 0-9. The ^ means not, so, not a letter, uppercase letter or number. The g at the end stands for global meaning it will not just find one match for the patern but all the matches
  3. The empty string is what to replace the patern with. So if it is not a upper/lower case letter or number character it will be replaced with nothing

Read about RegEx here

about 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