【发布时间】:2020-05-27 06:38:05
【问题描述】:
给定一个大字符串:
str = "Include all the information someone would need to answer your question ... ..."
如何仅通过python代码和正则表达式(而不是列表等)来获取该字符串中整个单词的索引;如果它是列表中的元素,则此索引是该单词的索引:
lst = str.split()
其中:“信息”一词的索引为3,“答案”的索引为8。
【问题讨论】:
-
你能否更详细地解释一下这个问题。
-
你的意思是
str.split().index('information')?为什么要用re模块重新发明轮子?
标签: python regex indexing substring word