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

90
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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