preg_match_all('/^([a-zA-Z0-9]+|[a-zA-Z0-9]**[a-zA-Z0-9]*)(.[a-zA-Z0-9]+){2,3}$/', $input, $output); print_r($output);