+ 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]
4 ответов
+ 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 @
+ 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'.
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')
0
Did you just answer your own question like it was to somebody else?