fork download
  1. import re
  2.  
  3.  
  4. lst = ['MEASUREMENT K02313 New York',
  5. 'MEASUREMENT K02338 London [BC:2.7.7.7]',
  6. 'MEASUREMENT K14761 Kairo [BC:1.2.-.-]',
  7. 'MEASUREMENT K03629 Berlin',
  8. 'MEASUREMENT K02470 Paris [BC:5.6.2.-]',
  9. 'MEASUREMENT K02469 Madrid [BC:5.43.2.2]'
  10. ]
  11. pattern = r"\bBC:(?:[0-9-]|[1-9][0-9]|[1-9][0-9][0-9])(?:\.(?:[0-9-]|[1-9][0-9]|[1-9][0-9][0-9])){3}"
  12.  
  13. print ([m.group() for s in lst for m in [re.search(pattern, s)] if m])
Success #stdin #stdout 0.03s 9720KB
stdin
Standard input is empty
stdout
['BC:2.7.7.7', 'BC:1.2.-.-', 'BC:5.6.2.-', 'BC:5.43.2.2']