fork download
  1. import re
  2.  
  3. strings = ["ggggg18-05-2018ggggg",
  4. "ggggg18-05-2018ggggg12345678",
  5. "ggggg18-05-18ggggg",
  6. "ggggg18-05-18ggggg12345678",
  7. "ggggg2018-05-18ggggg",
  8. "ggggg2018-05-18ggggg12345678",
  9. "ggggg18-05-123ggggg12345678"]
  10.  
  11. for str in strings:
  12. print(re.findall(r'(?<!\d)\d{2}-\d{2}-(?:\d{4}|\d{2})(?!\d)', str))
Success #stdin #stdout 0.01s 27800KB
stdin
Standard input is empty
stdout
['18-05-2018']
['18-05-2018']
['18-05-18']
['18-05-18']
[]
[]
[]