Advertisement
yordan_filipov

Extract valid names (RegEx)

Dec 9th, 2022
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. # Please extract all contacts from the text.
  2. # Valid contacts are like this - @Firstname#Familyname
  3. # INPUT:
  4. # Welcome to @ISI. If you need any help from HR you can write to
  5. # @Milo#Minderbinder. For any technical problems you should contact
  6. # @Major#Major or @Hristo#sTOIchkov. If you need any smart advises,
  7. # please contact @Ali#Baba or @John#Yossarian.
  8. # When you are sick, please stay at #Home.
  9.  
  10. import re
  11.  
  12. # Input from the user
  13. data = input()
  14.  
  15. # RegEx pattern
  16. pattern = r"@[A-Z][a-z]+#[A-Z][a-z]+"
  17.  
  18. result = re.finditer(pattern, data)
  19. # iterate through the valid names
  20. for el in result:
  21.     print(el.group())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement