fork download
  1. import re
  2.  
  3. pattern = r"\btarget\s*(\d+)|.*[t.](\d+)$"
  4. strings = [
  5. "abc123-Target 4-ufs",
  6. "abc123-target4-ufs",
  7. "geo.4",
  8. "j123T4"
  9. ]
  10.  
  11. for s in strings:
  12. matches = re.finditer(pattern, s, re.IGNORECASE)
  13. for matchNum, m in enumerate(matches):
  14. print ("target " + (m.group(2) if m.group(2) else m.group(1)))
Success #stdin #stdout 0.02s 9584KB
stdin
Standard input is empty
stdout
target 4
target 4
target 4
target 4