📌  相关文章
📜  在 Python 代码示例中查找字符串中子字符串的所有出现

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

代码示例2
import re 
 
# defining string  
str1 = "This dress looks good; you have good taste in clothes."
 
#defining substring 
substr = "good"
 
print("The original string is: " + str1) 
 
print("The substring to find: " + substr) 
 
result = [_.start() for _ in re.finditer(substr, str1)] 
 
print("The start indices of the substrings are : " + str(result))

# Output - 
# The original string is: This dress looks good; you have good taste in clothes.
# The substring to find: good
# The start indices of the substrings are : [17, 34]