fork download
  1. import re
  2. pattern = r"^.*\b(?:cart|order)\b.*|(\b\d{4,12}\b)"
  3.  
  4. text1 = 'the cart number is 1234 and 4567 that it!'
  5. text2 = "order 12345"
  6. text3 = "credit card is 0000 4567 and 3456"
  7. text4 = "i got 245 dollar"
  8. text5 = "the 4567 and 2345 "
  9.  
  10. strings = [
  11. text1,
  12. text2,
  13. text3,
  14. text4,
  15. text5
  16. ]
  17.  
  18. for string in strings:
  19. print([s.span() for s in re.finditer(pattern, string, re.M) if s])
  20.  
  21.  
Success #stdin #stdout 0.04s 9636KB
stdin
Standard input is empty
stdout
[(0, 41)]
[(0, 11)]
[(15, 19), (20, 24), (29, 33)]
[]
[(4, 8), (13, 17)]