a = 'stackoverflow'
b = 'stackofpancakes'
a[:[(x[0] == x[1]) for x in zip(a, b)].index(0)]
a = 'nothing in'
b = 'common'
a[:[(x[0] == x[1]) for x in zip(a, b)].index(0)]
Regexp finding longest common prefix of two strings