LeetCode | 判断子串下标

 

 

通过正则查找返回下标

 

import re
master = "AVERDXIVYERDIAN"
dev = "ERD"
for m in re.findall(f"{dev}", master):
    print(m)

list = [m.start() for m in re.finditer(f"{dev}", master)]
print(list)
if list:
    if list[0] + 1 >= 0:
        print(list[0] + 1)
    else:
        print("No")
else:
    print("No")

 

posted @ 2021-08-03 16:33  黄金国的大象  阅读(31)  评论(0编辑  收藏  举报