My Tech Scrap
Flipkart.com

Translate

Share |

Friday, 17 January 2025

Python - Extract emails using regex

Here's a simple python script to extract and format the emails:

Script

import re

input_text = "hj sdsd <jkkl.kll.o.v@blbla.com>; jsdsl lassd <jskdsd.uioo@blbla.com>;"

emails = re.findall(r'<([^>]+)>', input_text)

output = ','.join(f'"{email}"' for email in emails)

print(output)


Output

"jkkl.kll.o.v@blbla.com","jskdsd.uioo@blbla.com"

This script uses a regular expression to find all email addresses enclosed in angle brackets < > and formats them as requested.