📌  相关文章
📜  python 查找字符串中子字符串的所有元素 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:41.364000             🧑  作者: Mango

代码示例1
def find_all(a_str, sub):
    start = 0
    while True:
        start = a_str.find(sub, start)
        if start == -1: return
        yield start
        start += len(sub) # use start += 1 to find overlapping matches

list(find_all('spam spam spam spam', 'spam')) # [0, 5, 10, 15]