子串搜索

来源:互联网 发布:mysql 修改系统参数 编辑:程序博客网 时间:2024/05/16 10:31
>>> import re>>> string = 'test test test test'>>> string.find('test')  # 返回匹配字串的第一个下标0>>> string.rfind('test')  # 返回匹配字串的最后一个下标15>>> [m.start() for m in re.finditer('test', string)]  # 返回所有匹配子串下标[0, 5, 10, 15]


Ref:
http://stackoverflow.com/questions/4664850/find-all-occurrences-of-a-substring-in-python

0 0
原创粉丝点击