PHP regex for a word collection around a search phrase

后端 未结 2 1258
忘掉有多难
忘掉有多难 2021-01-06 07:08

Hi I am trying to create a regex that will do the following

grab 5 words before the search phrase (or x if there is only x words there) and 5 words after the search

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-06 07:43

    You can do the folowing (it is a bit computation heavy, so it woudn't be efficient for very long strings):

    Codepad example here

提交回复
热议问题