Advertisement
elena1234

RegEx in Python for word boundary

Feb 13th, 2022
1,028
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import re
  2.  
  3. pattern = re.compile(r"(^|(?<=\s))[a-zA-Z0-9]+[\-_\.]*\w+@\w+[\-_\.]*\w+\.[\w\.]+\b")
  4. text = input()
  5.  
  6. matches = pattern.finditer(text)
  7. for match in matches:
  8.     print(match.group())
  9.    
  10.    
  11. # valid emails: info@softuni-bulgaria.org,
  12. # kiki@hotmail.co.uk, no-reply@github.com,
  13. # s.peterson@mail.uu.net, info-bg@software-university.software.academy.
  14.  
  15. # invalid emails: --123@gmail.com, …@mail.bg,
  16. # .info@info.info, _steve@yahoo.cn, mike@helloworld, mike@.unknown.soft., s.johnson@invalid-.
  17.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement