找到所有以x或x开头的单词,并输出它们的位置
Input: w
Input: “When you are down and out, remember to keep your head up. When you are up and well, remember to keep your feet down.”
Output:
When : (1, 5)
When : (59, 63)
well : (79, 83)
import re
st=input()#w
pa='\\b(?i)'+st+'\\w+\\b'
pattern = re.compile(pa)
exampleString=input()
index = 0
while True:
matchResult = pattern.search(exampleString,index)
if not matchResult:
break
print(matchResult.group(0),'.',matchResult.span(0))
index=matchResult.end(0)
没看懂题目什么意思