fork download
  1. import re
  2. pattern = re.compile( r"\b\d{2,12}\b" )
  3. pattern_valid = re.compile( r"^\s*(?:(the|an?)\s+)?(cart|order)\b|\bdollar\s*$", re.I )
  4. texts = ['the cart number is 1234 and 4567 that it!',
  5. "order number note down 12345",
  6. "credit card is 0000 and 3456",
  7. "the 4567",
  8. "i got 245 dollar"]
  9. for text in texts:
  10. if not pattern_valid.search(text):
  11. print(text, pattern.findall(text), sep=" => ")
Success #stdin #stdout 0.04s 9600KB
stdin
Standard input is empty
stdout
credit card is 0000 and 3456 => ['0000', '3456']
the 4567 => ['4567']