正则表达式:在特定单词前后找到一些

I'm trying to find to find anything with an included word. So far I've got (r'>(.*(word)?)</a>' but I'm having some trouble. What I want is to have some text (word) some text.

评论
  • adicta
    adicta 回复

    Using re.findall:

    re.findall('(.+)\(word\)(.+)','some text (word) some text')
    

    给出:

    [('some text ', ' some text')]
    

    一个例子:

    >>> text = 'wow! python (word) is amazing!'
    >>> re.findall('(.+)\(word\)(.+)',text)
    [('wow! python ', ' is amazing!')]