0

I need to match complete sentences ending at the full stop, but I'm stuck on trying to skip false dots.
To keep it simple, I've started with this syntax [^.]+[^ ] which works fine with normal sentences, but, as you can see, it breaks at every dots.

My regex101

So, at the first sentence, the result should be:

Recent studies have described a pattern associated with specific object (e.g., face-related and building-related) in human occipito-temporal cortex.

and so on.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Neuran
  • 137
  • 10

2 Answers2

1

Just use a lookahead to set the condition as match upto a dot which must be followed by a space or end of the line anchor $.

(.*?\.)(?=\s|$)

DEMO

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
0

Expanding upon this, here is a regex that doesn't use reluctant matching and potentially more efficient:

(?:[^.]+|\.\S)+\.

And if you would like to match the sentences themselves, and remove the one trending space that you would get from using the regex of the accepted answer, you can use this:

\S(?:[^.]+|\.\S)+\.

Here is a regex demo.

Unihedron
  • 10,902
  • 13
  • 62
  • 72