python中查找 字符串 中的 多个子串
文章目录
以下代码:查找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)
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论