php preg_match return position of last match

前端 未结 4 563
南旧
南旧 2021-01-11 17:32

With

preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE); 

is it possible to search a string in reverse? ie. return the position

4条回答
  •  滥情空心
    2021-01-11 18:17

    preg_match does not support reverse searching because it is not neccessary.

    You can create a RegExp that contains a greedy (that is default) lookahead that matches anything (like (?<=.*)stuff ). This way you should get the last occurence of your match.

    detailed information from official documentation here: preg_match

提交回复
热议问题