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

270
Vistas
How to stop RegEx match at the end of a sentence?

I want to split the text into chunks of a given character length.
The split should happen on the next whitespace character after hitting a specified character count.

This is my regex:

\S+.{0,14}(?= |$)

And here is sample input:

When done correctly, heat exposure offers tremendous benefits. However, it is extremely dangerous to use temperatures that are too hot. What is too hot? That will depend.

I’ve prepared a working example: https://regex101.com/r/JGJvtm/3

However, I additionally need to end a given chunk, when it encounters the end of a sentence [!.?](?= |$)

As seen in the example: “…benefits. However, it…” is now considered one chunk.
The split should happen after the point, and the next chunk should start with “However", even though the character limit wasn’t yet reached.

Feel free to propose an entirely different regex, whatever works.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

There is an issue with your current regex: The \S+ will capture potentially long words, and the counting of 14 characters only starts after that match. According to your description also the letters of that first word should count towards the limit.

I would suggest this regex:

(?=\S)((?![!?.](\s|$)).){0,13}\S*

  • (?=\S) ensures that the match starts with a non-white-space character without actually capturing it yet.
  • (?![!?.](\s|$)) ensures the next character is not a sentence terminator followed by white space or by the end of the input.
  • ( .){0,13} matches up to 13 characters
  • \S* will capture the remaining non-white-space characters.
about 4 years ago · Santiago Trujillo Denunciar

0

\S.{13}\S*\s

https://regex101.com/r/2g4TBr/1

start with 1 non-space, then any 13 chars, then catch the "tail" before the space

about 4 years ago · Santiago Trujillo 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