+ 2

Why I need to use reg-ex if I can use for loops s = "Please contact info@sololearn.com for assistance" email = [i for i in s.split(' ') if '@' in i]

10th Nov 2016, 10:08 AM
Alexander Veledzimovich
4 Answers
+ 2
cause in other cases you can have @ symbol in no email words forma example. Regular expressions can specify a more complex email format, analysing all the components in an email, not only that it has an @
22nd Nov 2016, 2:21 PM
Federico Beltrame
Federico Beltrame - avatar
+ 1
No. There was another name on that response earlier; it switched around 13:00 UTC. That answer also has a typo; it needs a \ for the 2nd 'w'.
10th Nov 2016, 7:49 PM
Kirk Schafer
Kirk Schafer - avatar
0
I understand trouble with for loop, but also you have mistake. If we have sample like this: s= 'Sasha Veledzimovich veledz@gmail.com, zen-time@gmail.com, python@gmail.url.com.' You code will provide e-mail with dot at the end. We can fix it pat=r"[\w\.-]+@[w\.-]+\.[\w]+" Also you have parenthesis. They are not nessessary. If we use re.findall we have emails separated by groups. For example : ('python', 'gmail.url', '.com')
10th Nov 2016, 11:07 AM
Alexander Veledzimovich
0
Did you just answer your own question like it was to somebody else?
10th Nov 2016, 5:29 PM
LaserHydra
LaserHydra - avatar