added error handling for regex