fixed preg match function