elena1234

finditer in Python

Feb 11th, 2022 (edited)
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import re
  2.  
  3. pattern = re.compile("\d+")
  4. text = input()
  5. all_matches = []
  6. while True:
  7.     if len(text) == 0:
  8.         break
  9.     matches = pattern.finditer(text)
  10.     for match in matches:
  11.         all_matches.append(match.group())
  12.     text = input()
  13.    
  14. for element in all_matches:
  15.     print(element, end=" ")
  16.    
  17.  
  18.  
  19. input:
  20. The300
  21. What is that?
  22. I think it's the 3rd movie
  23. Lets watch it at 22:45
  24.  
  25. output:
  26. 300 3 22 45
Add Comment
Please, Sign In to add comment