To retrieve the index of all the occurrences of a word in the string (say a statement), Python, like most of the programming languages supports the regular expression module as a built-in module. Or if we don't want the overhead of using the regular expressions, we could also use the str.index() in an iteration to get the index and also using the comprehension.
为了检索字符串中某个单词所有出现的索引 (例如一条语句),Python与大多数编程语言一样,将正则表达式模块作为内置模块来支持。 或者,如果我们不想使用正则表达式的开销,我们也可以在迭代中使用str.index()来获取索引,也可以使用comprehension 。
1)使用正则表达式模块 (1) Using the regular expression module)
Example:
例:
The below example, explains the usage of the regex modu