什么是匹配特定字符串之上的所有正则表达式?

时间:2016-06-02 09:37:22

标签: php regex

什么是匹配特定字符串上方文本中所有内容的正则表达式?

字符串为=============REPLY ABOVE THIS LINE=============,我希望使用 PHP

获取其上方的所有内容

示例文字

this is a sample text here i want to match using regex. because it is above the following line 
=============REPLY ABOVE THIS LINE=============
here is below the line

所以正则表达式只返回

this is a sample text here i want to match using regex. because it is above the following line 

1 个答案:

答案 0 :(得分:1)

为什么不这样做呢?

$input = "this is a sample text here i want to match using regex. because it is above the following line =============REPLY ABOVE THIS LINE============= here is below the line"

$pieces = explode("=============REPLY ABOVE THIS LINE=============", $input);

$above_line = trim($pieces[0]);

$below_line = trim($pieces[1]);