Replace try/catch with regex match.