import re
strings = ["ggggg18-05-2018ggggg",
"ggggg18-05-2018ggggg12345678",
"ggggg18-05-18ggggg",
"ggggg18-05-18ggggg12345678",
"ggggg2018-05-18ggggg",
"ggggg2018-05-18ggggg12345678",
"ggggg18-05-123ggggg12345678"]
for str in strings:
print(re.findall(r'(?<!\d)\d{2}-\d{2}-(?:\d{4}|\d{2})(?!\d)', str))
aW1wb3J0IHJlCgpzdHJpbmdzID0gWyJnZ2dnZzE4LTA1LTIwMThnZ2dnZyIsCiJnZ2dnZzE4LTA1LTIwMThnZ2dnZzEyMzQ1Njc4IiwKImdnZ2dnMTgtMDUtMThnZ2dnZyIsCiJnZ2dnZzE4LTA1LTE4Z2dnZ2cxMjM0NTY3OCIsCiJnZ2dnZzIwMTgtMDUtMThnZ2dnZyIsCiJnZ2dnZzIwMTgtMDUtMThnZ2dnZzEyMzQ1Njc4IiwKImdnZ2dnMTgtMDUtMTIzZ2dnZ2cxMjM0NTY3OCJdCgpmb3Igc3RyIGluIHN0cmluZ3M6CglwcmludChyZS5maW5kYWxsKHInKD88IVxkKVxkezJ9LVxkezJ9LSg/OlxkezR9fFxkezJ9KSg/IVxkKScsIHN0cikp