Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

59
Vistas
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

7 months ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

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

7 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.