关于python: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)

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理