Regex Not Matching Mixed Case Email Addresses in Python - Case Sensitivity guide
I'm updating my dependencies and I'm attempting to set up I've been struggling with this for a few days now and could really use some help... I'm trying to validate email addresses using a regex pattern, but I keep running into issues with mixed case email addresses not matching. My current pattern is meant to capture standard email formats, but it also seems to unexpected result with variations in letter casing. I am using Python 3.9 with the `re` module for regex operations. The pattern I'm using looks like this: ```python import re email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' emails = ['test@example.com', 'Test@Example.com', 'TEST@EXAMPLE.COM', 'invalid-email', 'test@.com'] for email in emails: if re.match(email_pattern, email): print(f'{email} is valid') else: print(f'{email} is invalid') ``` When I run this, I get the expected results for lowercase emails, but it fails to recognize any uppercase versions as valid. I suspect it has to do with case sensitivity in regex. I tried adding the `re.IGNORECASE` flag like so: ```python for email in emails: if re.match(email_pattern, email, re.IGNORECASE): print(f'{email} is valid') else: print(f'{email} is invalid') ``` However, this doesn't seem to solve the scenario, as I still get 'invalid' for the mixed-case versions. Am I missing something in my regex pattern, or is there another configuration I need to apply? I would really appreciate any insights or fixes for this scenario. Thank you! Any ideas what could be causing this? Has anyone else encountered this? I'm working in a Windows 10 environment. What are your experiences with this? The project is a web app built with Python.