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

201
Vistas
split function is not working with the regex provided

this is my take on the problem. i have successfully passed 3/4. the only thing messing up my solution is that extra white space after ‘telebubbles’. how do i progress further? i’m not good with replace.

function spinalCase(str) {
let k=str.split(/[\s-_]?(?=[A-Z])/g).join('-').toLowerCase()
console.log(k)
return k
}

spinalCase('This Is Spinal Tap');//passed
spinalCase("thisIsSpinalTap")//passed
spinalCase("The_Andy_Griffith_Show")//passed
spinalCase("Teletubbies say Eh-oh")//not working
spinalCase("AllThe-small Things")//passed

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

0

You may use this regex to fix your problem:

/\s+|[-_]*(?=[A-Z])/

Code:

function spinalCase(str) {
    let k = str.split(/\s+|[-_]*(?=[A-Z])/g).join('-').toLowerCase();
    console.log(k);
    return k;
}

spinalCase('This Is Spinal Tap'); //passed
spinalCase("thisIsSpinalTap"); //passed
spinalCase("The_Andy_Griffith_Show"); //passed
spinalCase("Teletubbies say Eh-oh"); //passed
spinalCase("AllThe-small Things"); //passed

RegEx Details:

  • \s+: Match 1+ whitespaces
  • |: OR
  • [-_]*(?=[A-Z]): Match 0 or more of underscore or hyphen if that followed by an uppercase letter
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