Search code examples
javascriptregexperiodsentence

Match full sentences skipping spurious dots


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.


Solution

  • 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