Search in a string and obtain the 2 words before and after the match in Python

后端 未结 4 1942
伪装坚强ぢ
伪装坚强ぢ 2021-01-19 15:39

I\'m using Python to search some words (also multi-token) in a description (string).

To do that I\'m using a regex like this

    result = re.search(w         


        
4条回答
  •  迷失自我
    2021-01-19 16:18

    Try this regex: ((?:[a-z,]+\s+){0,2})here is\s+((?:[a-z,]+\s*){0,2})

    with re.findall and re.IGNORECASE set

    Demo

提交回复
热议问题