Get index of first dot with letter in a string

Tags: ,

I have a string like this one: (not a real hostname, just an example)

I’ve already tinkered around with preg_split which didn’t gave me the good result.

Anyway, I’d like to get this result:


Sorry, for not showing directly what I did with preg_split(), I already thought about doing that, however, it would have resulted into a completely wrong result when there are numbers within the domain.

preg_split( "/[0-9].[a-z]/", $hostAddr)

put out

but with it would have resulted in



Try using this regular expression to detect everything after the first . followed by a single letter:

$hostname = '';
$matches = array();
preg_match('/(?<=.)[a-zA-Z].+/', $hostname, $matches);
echo $matches[0];

Source: stackoverflow