- substr: documentation ( source)
- preg_match: documentation ( source)
<?php
$name = "Avalone, Doris B. - 09-01-2014 - a00005213.exe";
$searcharr = preg_match("/^\w+/", $name, $matches);
if (strlen($matches[0]) >= 4) $searchstr = substr($matches[0], 0 ,4);
else $searchstr = $matches[0];
print($searchstr);