关于python:python中查找-字符串-中的-多个子串

3次阅读

共计 300 个字符,预计需要花费 1 分钟才能阅读完成。

以下代码:查找 content 字符串中的所有子串 abc

import re
 
content = 'abc edf abc 1234 abc 45'
regex = re.compile(r'abc')  ## 待查找字符串 abc
tels_obj = regex.finditer(content)
tels_list = []
for tel in tels_obj:
    tels_list.append(tel.group())
    print(tel)
    print(tel.span())  ## 每个子串的开始和完结地位
    print(tel.start())  ## 每个子串的开始地位
    print(tel.end())   ## 每个子串的完结地位
print(tels_list)
正文完
 0