- preg_match: documentation ( source)
<?php
$test = 'aaa.bbb.ccc.ddd.eee.fff.ggg.hhh';
$max = 10;
$retry = 1;
do {
echo $test . "\n";
preg_match("/^.+?\.(.+)$/", $test, $result);
if (false === $result) throw new \InvalidArgumentException('invalid');
$test = $result[1];
} while ($retry++ < $max);