Advertisement
elena1234

RegEx in Python for word boundary

Feb 13th, 2022
1,060
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: [email protected],
  12.  
  13. # invalid emails: [email protected], …@mail.bg,
  14. # [email protected], [email protected], mike@helloworld, [email protected]., s.johnson@invalid-.
  15.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement