Use try function block to catch regex_error.