Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python regex: findall with parentheses inside

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".

[]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading