while si < sl: if pi < pl and (s[si] == p[pi] or p[pi] == '?'): si += 1 pi += 1 # Check if * can be used as empty string elif pi < pl and p[pi] == '*': siLast = si starIndex = pi pi += 1 # Not match but have *. Try s[siLast+1] and p[starIndex+1] elif starIndex != -1: siLast += 1 si = siLast pi = starIndex + 1 else: # Not match and have no * returnFalse