-1

I am using the following regex to extract email from message.

Hi Helpdesk, I'm reaching out to you to ask for help about an accident I had. Is this the correct contact for accidental damages?\nTommaso Massari\nData Scientist\ntommaso_massari@gmail.com

My code:

from_email = str(re.findall('\s*[a-zA-Z]*.*\s*[\\n]([a-zA-Z]*.*[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,})',firstrow['message']))

It doesn't return anything in Python.

Expected output: tommaso_massari@gmail.com

tripleee
  • 175,061
  • 34
  • 275
  • 318
Rifatt Mir
  • 1
  • 1
  • 1

1 Answers1

-1

You're looking for the DOTALL flag.

https://docs.python.org/3/library/re.html#re.DOTALL

Also, sometimes the MULTILINE flag is relevant for text containing newlines.

J_H
  • 17,926
  • 4
  • 24
  • 44