Python Regex For Email Addresses, Need To Weed Out Dot Dash
I have created this regular expression to weed out obviously wrong email addresses. For my large data set it works for 98% of cases. pattern = re.compile('^([a-zA-Z0-9._-]+)([a-zA
Solution 1:
You can use negative look ahead assertion here
^(?!.*\.-.*$|.*-\..*$)([a-zA-Z0-9._-]+)([a-zA-Z0-9]@[a-zA-Z0-9])([a-zA-Z0-9.-]+)([a-zA-Z0-9]\.[a-zA-Z]{2,3})$
More specific one will be
^(?![a-zA-Z0-9._@-]*\.-[a-zA-Z0-9._@-]*$|[a-zA-Z0-9._-@]*-\.[a-zA-Z0-9._-@]*$)([a-zA-Z0-9._-]+)([a-zA-Z0-9]@[a-zA-Z0-9])([a-zA-Z0-9.-]+)([a-zA-Z0-9]\.[a-zA-Z]{2,3})$
Or in case ..
, --
, ...
, etc. are not allowed then you can use
^(?![a-zA-Z0-9._@-]*[.-]{2,}[a-zA-Z0-9._@-]*$)([a-zA-Z0-9._-]+)([a-zA-Z0-9]@[a-zA-Z0-9])([a-zA-Z0-9.-]+)([a-zA-Z0-9]\.[a-zA-Z]{2,3})$
Post a Comment for "Python Regex For Email Addresses, Need To Weed Out Dot Dash"