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

132
Vistas
Don't match if there is an extra period at the end of a sentence

I'm using this regex:

\n\n|(?<=[^,][."*?!\^])(?!\.)[ ](?=["*]?[A-Z])

To match the empty space after a sentence (I'm using [ ] to show you the matches):

First sentence.[ ]Middle a sentence..[ ]Last sentence.

First sentence?[ ]Middle a sentence!.[ ]Last sentence.

"First sentence," Middle a sentence..[ ]Last sentence.

"First sentence."[ ]"Middle a sentence.".[ ]Last sentence.

It's worked fine so far. But now I want the regex not to match when there are .., ?., !., ."., etc. at the end of a sentence. In other words, when there's an extra period:

First sentence.[ ]Middle a sentence.. Last sentence.

First sentence?[ ]Middle a sentence!. Last sentence.

"First sentence," Middle a sentence.. Last sentence.

"First sentence."[ ]"Middle a sentence.". Last sentence.

I thought adding an (?!\.) would do the trick:

\n\n|(?<=[^,][."*?!\^])(?!\.)[ ](?=["*]?[A-Z])

But as you can see here, it's still matching the empty spaces after the extra period.

Why is this and how to fix it?

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

0

You can extend this negated class [^,] with all other characters that you don't want to occur as one-before-last character in a sentence.

So like: [^,.]

If however you want to allow ." to end a sentence, and only want to avoid two points (or !. and ".), then put your look around condition there as look-back:

(?<=[^,][."*?!\^])(?<![.!?"]\.)

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