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

237
Vistas
Regex stack expressions to split long words into chunks

I tried to stack two regex expressions, but without any luck.

In my case I need to find all words with length 50 and larger

\w{50,}

and now I need to split only those matches in chunks by 10 characters.

.{1,10}

I was unable to apply second expression to the first expression matches. Do you've any ideas?

Thanks!!!

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

0

Javascript replace() can take a function as replacement.

str = str.replace(/\w{50,}/, function(m) {
  return m.match(/.{1,10}/g).join(' ');
});

See this demo at tio.run - or a bit shorter one:

str = str.replace(/\w{50,}/, m => m.match(/.{1,10}/g).join(' '));

No idea if it's possible in JS with just one regex. In PCRE: (?:\G\B|\b(?=\w{50}))\w{10}\B\K

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