<?php
$strings = ['This is. a.. test...',
'This is a........... test.',
'...This is. a.. ..test',
'This is a test',
'This. is... a. test.'
];
foreach ($strings as $string) {
if (preg_match('~(?<!\.)\.{3}(?!\.)~', $string)) {
echo "Yes, found an occurrence of not more than 3 dots in a row ($string)";
} else {
echo "Nope, no occurrence of exactly 3 dots in a row ($string)";
}
echo "\n";
}
Yes, found an occurrence of not more than 3 dots in a row (This is. a.. test...)
Nope, no occurrence of exactly 3 dots in a row (This is a........... test.)
Yes, found an occurrence of not more than 3 dots in a row (...This is. a.. ..test)
Nope, no occurrence of exactly 3 dots in a row (This is a test)
Yes, found an occurrence of not more than 3 dots in a row (This. is... a. test.)