def find_substring_ignore_special_chars(s, substr):
s = s.upper()
substr = substr.upper()
clean_s, dummy_subs_in_s = re.subn('[^A-Z0-9]', '', s)
clean_substr, dummy_subs_in_substr = re.subn('[^A-Z0-9]', '', substr)
startIndex = clean_s.find(clean_substr)
if startIndex != -1:
i = 0
real_index = 0
re_alphanum = re.compile('[A-Z0-9]')
for real_index, char in enumerate(s):
if re_alphanum.match(char):
i += 1
if i > startIndex:
break
return real_index
else:
return -1
评论列表
文章目录