Fix segmentation fault caused by invalid characters in regular expressions.