added error handling for regex match
added error handling for regex match