Fix an important bug when regex is invalid