What is wrong with this regex for matching emails?

Peng Yu pengyu.ut at gmail.com
Sun Dec 17 10:29:47 EST 2017


Hi,

I would like to extract "abc at efg.hij.xyz". But it only shows ".hij".
Does anybody see what is wrong with it? Thanks.

$ cat main.py
#!/usr/bin/env python
# vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8:

import re
email_regex = re.compile('[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)')
s = 'abc at efg.hij.xyz.'
for email in re.findall(email_regex, s):
    print email

$ ./main.py
.hij

-- 
Regards,
Peng



More information about the Python-list mailing list