Make sure the regex is not empty before calling preg_match