This could be neater as a preg_match