Python - Locating the position of a regex match in a string?

后端 未结 3 2020
余生分开走
余生分开走 2020-12-02 16:40

I\'m currently using regular expressions to search through RSS feeds to find if certain words and phrases are mentioned, and would then like to extract the text on either si

3条回答
  •  日久生厌
    2020-12-02 17:14

    re.Match objects have a number of methods to help you with this:

    >>> m = re.search("is", String)
    >>> m.span()
    (2, 4)
    >>> m.start()
    2
    >>> m.end()
    4
    

提交回复
热议问题