Regex to get rid of everything past the first sentence in a string in php
Posted
by
andufo
on Stack Overflow
See other posts from Stack Overflow
or by andufo
Published on 2011-11-29T15:32:10Z
Indexed on
2011/11/29
17:49 UTC
Read the original article
Hit count: 251
I need to get rid of everything after the first dot (if there is more than 1 sentence), but at the same time, cases like e.g. have to be omited.
Some line e.g., when people do something. Extra content.
Some line (some parenthesis). Extra content.
I need to get rid of the "Extra content.". The returning value should be:
Some line e.g., when people do something.
Some line (some parenthesis).
So far I've come with this regex taken from other threads, but it only finds the dots and split the string into an array.
preg_replace('/(?<!\.)\.(?!(\s|$|\,|\w\.))/','',$text);
Any ideas? Thanks.
© Stack Overflow or respective owner