x="From Daniel: dani78.72.dom@gmail.com UTC-8"
y=re.findall("^From (\S+@\S+)",x)
I want the output to be:
[dani78.72.dom@gmail.com]
but it gives me an empty list, I really need the line to start with "from".
[]
>Solution :
With your shown samples and attempts, please try following python3 code. Using Python’s re module here and its findall function.
Here is the Online Demo for used regex.
import re
x="From Daniel: dani78.72.dom@gmail.com UTC-8"
re.findall(r'^From\s+.*?:\s(\S+@\S+)\s+UTC-\d+$',x)
['dani78.72.dom@gmail.com']