Reputation: 13
x="From Daniel: [email protected] UTC-8"
y=re.findall("^From (\S+@\S+)",x)
I want the output to be:
[[email protected]]
but it gives me an empty list, I really need the line to start with "From".
[]
Upvotes: 1
Views: 48
Reputation: 133720
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: [email protected] UTC-8"
re.findall(r'^From\s+.*?:\s(\S+@\S+)\s+UTC-\d+$',x)
['[email protected]']
Upvotes: 1