Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
Write a regular expression that finds strings of the following kind

The task itself looks like this: Given string 'ave a#b a2b a$b a4b a5b a-b acb'. Write a regular expression that finds strings of the following kind: the letters 'a' and 'b' are at the edges, and there is neither a letter nor a number between them.

It's just really hard for me to make sense of it. But I was able to write something like:

'ave a#b a2b a$b a4b a5b a-b acb'.replace(/a\Wb/g, ""),

but it works by replacing only the values I need to output and leaving 'ave a2b a4b a5b acb', but I just need to remove everything except 'a#b a$b a-b'. Can you help me with that?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can match all occurrences of the \ba[^\sa-zA-Z0-9]b\b pattern that matches a not preceded with any word char, then any char other than whitespace, letters and digits, and then a b not followed by a word char, and then join the output with a space:

console.log(
  'ave a#b a2b a$b a4b a5b a-b acb'.match(/\ba[^\sa-zA-Z0-9]b\b/g).join(" ")
)

See the regex demo.

Note: if the expected matches occur in between whitespaces or start/end of string, you might need to replace word boundaries with whitespace boundaries, /(?<!\S)a[^\sa-zA-Z0-9]b(?!\S)/g.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda