Finding words after keyword in python

后端 未结 9 1931
清酒与你
清酒与你 2020-12-08 20:19

I want to find words that appear after a keyword (specified and searched by me) and print out the result. I know that i am suppose to use regex to do it, and i tried it out

9条回答
  •  没有蜡笔的小新
    2020-12-08 20:57

    This will work out for u : work name\s\w+\s(\w+)

    >>> s = 'hi my name is ryan, and i am new to python and would like to learn more'
    >>> m = re.search('name\s\w+\s(\w+)',s)
    >>> m.group(0)
    'name is ryan'
    >>>> m.group(1)
    'ryan'
    

提交回复
热议问题