I use this function to remove three dots before or after a newline:
private function trimThreeDots(string $text): string {
$threeDotsAtTheBeginning = '((^|[\n]{1})[\\.]{3})';
$threeDotsAtTheEnd = '([\\.]{3}[\n]{1})';
$pattern = '/' . $threeDotsAtTheBeginning . '|' . $threeDotsAtTheEnd . '/';
return preg_replace_callback($pattern, function ($str) {
return str_replace("...", "", $str[0]);
}, $text);
}
It works, except that in case that I have a string like this one:
"Bla bla bla...
...bla bla bla"
I only get a single match. But I want to get two matches, because I need to remove both occurrences of three dots. I wonder if maybe there is a more straightforward and efficient way to write this regex and getting two matches in the above case?