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

91
Vistas
What is the regular expresion for all capital letters and all non alphabetic characters

I need the regex for all non alphabetic character and capital letters only.

let str = "ThisIs-an_example";

What regex should I use for separating the words correctly using arr.join so that it is "this is an example"

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

0

Something like this?

let str = "ThisIs-an_example";
let result = str.replace(/([A-Z])/g, ' $1').toLowerCase().trim().replace(/[^a-z]/g, ' ');

Not quite what you asked for (array), but does the job.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You've got a couple of issues. First is that split doesn't include the separator, so if you just split on any upper case or non-letter character, then you'll end up losing the uppercased letters. (see first example).

So you can split on non-alpha characters OR a zero width assertion of an upper case character following something (see second example), but then you have an issue with the casing in the final string. You'll have to map back if you want to deal with that (see third example).

let str = "ThisIs-an_example";
let arr = str.split(/[^a-z]/);
console.log(arr);

arr = str.split(/[^A-Za-z]|(?=[A-Z])/);

console.log(arr.join(" "));

let cased = arr.map((a,i)=>{return i>0 ? a.toLowerCase() : a});

console.log(cased.join(" "));

Also note that this is going to split on any numbers that are included. If you expect numbers to ever appear, you will have to modify the expression.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can split on a non-alphabetic character or a lookahead for an uppercase letter.

let str = "ThisIs-an_example";
let parts = str.split(/(?=[A-Z])|[^a-z]/);
console.log(parts);
console.log(parts.join(' ').toLowerCase());

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