python - Regular Expression for Email address -



python - Regular Expression for Email address -

here weird regular look emails .

we can have various kind of email addresses

string1@somemail.com

string1@somemail.co.in

string1.string2@somemail.com

string1.string2@somemail.co.in

the next regular look can find of mails above

email2="santa.banta@gmail.co.in" email1="arindam31@yahoo.co.in'" email="bogusemail123@sillymail.com" email3="santa.banta.manta@gmail.co.in" email4="santa.banta.manta@gmail.co.in.xv.fg.gh" email5="abc.dcf@ghj.org" email6="santa.banta.manta@gmail.co.in.org" re.search('\w+[.|\w]\w+@\w+[.]\w+[.|\w+]\w+',email) x=re.search('\w+[.|\w]\w+@\w+[.]\w+[.|\w+]\w+',email2) x.group() santa.banta@gmail.co.in' x=re.search('\w+[.|\w]\w+@\w+[.]\w+[.|\w+]\w+',email1) x.group() arindam31@yahoo.co.in' x=re.search('\w+[.|\w]\w+@\w+[.]\w+[.|\w+]\w+',email) x.group() 'bogusemail123@sillymail.com'

this seems complicated right...

i generalized bit....

x=re.search('(\w+[.|\w])*@(\w+[.])*\w+',email4) x.group() 'santa.banta.manta@gmail.co.in.xv.fg.gh'

the above regular look can observe type of combination...

now if want email address ending '.in' or '.com' can add together variation...

x=re.search('(\w+[.|\w])*@(\w+[.])*(com$|in$)',email)

you can seek out on various combinations.... if look not fit anywhere , tell me .

some assumptions have used : email address(username) wont contain special characters , words or numbers.

as answered on stackoverflow, correct regexp emails way more complicated that.

python

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -