0

I have a very long string, which contains in addition to other characters even email addresses.

As that:

>>> s= “fedcantona datto, ernest william, pasquale <b>lops</b>, till plbaum, ...pasqale.  <b>email</b>: pasquale@gmail.com pagina web personale: http://.www. do. aggigi .il ...fanei ana tel: +34-54285, e-<b>mail</b>: fanli@gmail.com. .impedovo ... <b>lops</b> pale, tel: +9-54285, e-<b>mail</b>:  <b>lops</b>, g semo, p .bile ... b mehta, c niederee, a stewart, m demm”

I want to have as output the first email address of the string, the only thing I know is that all the email addresses ending with "@gmail.com". I wrote this:

>>> print  re.findall("(%s)(@gmail.it)", s)[0]

But it does not work, what I did wrong?

idjaw
  • 25,487
  • 7
  • 64
  • 83
roxana21
  • 3
  • 1

1 Answers1

0

you can use the search() function to find only the first occurrence

>>> rex=re.compile(r"\S+@gmail\.\w+")
>>> rex.search(s).group()
'pasquale@gmail.com'
LonelyCpp
  • 2,533
  • 1
  • 17
  • 36