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

153
Vistas
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 Respuestas
Responde la pregunta

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