Python Regex to validate an email I have written this regex to validate an email. It seems to work fine. Can someone advise on the regex used? Does it work properly or can be done in a better way?
pattern=r&quot;^[A-Za-z]+[-_$.A-Za-z]*@[A-Za-z]*\.[A-Za-z]+$&quot;
x=re.search(pattern,&quot;abc.xyz@gmail.com)
print x

Note: I have used x and print as Code Review needs minimum 3 lines of code.
That regex will not properly validate the format of an email address. Many web sites get it wrong when validating email addresses.
According to RFC5322, the local part of an address (the part before the @) can contain one or more text strings separated by .s.  The test strings can include letters, numbers, and any of these characters: ! # $ % &amp; ' * + - / = ? ^ _ { | } ~ &quot; or a back tick.  Alternatively, the local part can be a quoted string.  There can be comments in () and possibly whitespace in some places.
That's just for the local part using only US-ASCII characters.  There are other RFCs that describe the domain (after the @) and addresses with non-ASCII (e.g., Unicode) characters.