def count_overlapping(string, pattern):
count = 0
start = -1
while True:
start = string.find(pattern, start + 1)
if start < 0:
return count
count += 1
mystr = '^_^_^-_-'
print(count_overlapping(mystr, '^_^'))
print(count_overlapping(mystr, '-_-'))
print(count_overlapping(mystr, ''))
print(count_overlapping(mystr, 'x'))
ZGVmIGNvdW50X292ZXJsYXBwaW5nKHN0cmluZywgcGF0dGVybik6CiAgICBjb3VudCA9IDAKICAgIHN0YXJ0ID0gLTEKICAgIHdoaWxlIFRydWU6CiAgICAgICAgc3RhcnQgPSBzdHJpbmcuZmluZChwYXR0ZXJuLCBzdGFydCArIDEpCiAgICAgICAgaWYgc3RhcnQgPCAwOgogICAgICAgICAgICByZXR1cm4gY291bnQKICAgICAgICBjb3VudCArPSAxCgpteXN0ciA9ICdeX15fXi1fLScKcHJpbnQoY291bnRfb3ZlcmxhcHBpbmcobXlzdHIsICdeX14nKSkKcHJpbnQoY291bnRfb3ZlcmxhcHBpbmcobXlzdHIsICctXy0nKSkKcHJpbnQoY291bnRfb3ZlcmxhcHBpbmcobXlzdHIsICcnKSkKcHJpbnQoY291bnRfb3ZlcmxhcHBpbmcobXlzdHIsICd4Jykp