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

152
Visualizações
Finding consecutive characters but ignore space & case?

I'm looking to match the following strings so that I can later truncate them from the string in JS. For ex: matched: i like eeeting pie and a a a a a bananas. matched: My name iIIs John Doe and A a A a AA AAA I'm cool.

This is the regex I currently have, but it doesn't match if there is a space in between or if there are more than 3 consecutive letters:

(.)\1\1
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use

/(\S)(?:\s*\1){2,}/gi
/\b(\S)(?:\s*\1){2,}/gi

If you need to make sure you only start matching at the word boundary, you need to use the second regex.

See the JavaScript demo:

const text = "i like eeeting pie and a a a a a bananas. My name iIIs John Doe and A a A a AA AAA I'm cool.";
const re = /(\S)(?:\s*\1){2,}/gi;
document.body.innerHTML = text.replace(re, '<b>$&</b>')
// Second regex demo:
document.body.innerHTML += "<br/>" + text.replace(/\b(\S)(?:\s*\1){2,}/gi, '<b>$&</b>')

The regex has the i case insensitive flag and matches

  • (\S) - Group 1: any non-whitespace char
  • (?:\s*\1){2,} - two or more occurrences of
    • \s* - zero or more whitespaces
    • \1 - the value of Group 1.

See the regex scheme:

enter image description here

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