Advertisement
Nenogzar

Untitled

Oct 28th, 2023
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import re
  2.  
  3. with open("split.txt", "r") as file:
  4.     text = file.read()
  5.  
  6. pattern = r"(^|(?<=\s))([a-z0-9]+[\.\-\_a-z]*)@([a-z\-]+)(\.[a-z]+)+\b"
  7. matches = re.finditer(pattern, text)
  8.  
  9. list_with_emails = []
  10. list_with_names = []
  11. for match in matches:
  12.     email = match.group()
  13.     username = match.group(2)
  14.     list_with_names.append(username)
  15.     list_with_emails.append(email)
  16.     start_index = match.start()
  17.     end_index = match.end()
  18.  
  19.     print(f"Email: {email}")
  20.     print(f"Start Index: {start_index}")
  21.     print(f"End Index: {end_index}")
  22.     print()
  23.  
  24. print(*list_with_emails, sep=", ")
  25. print(*list_with_names, sep=", ")
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement