Regex检查最后一段中的字符串


Regex To check that string in last paragraph

我有一个类似的文本

Hello this is test 
Text:12563
Test This is also Test.This is test

现在这里的文本:12563不是在最后一段,但如果我有一个像这样的文本

Hello this is test     
Test This is also Test.
Text:12563
This is test

文本:12563在给定文本的最后一段中。现在我必须用preg_match_all函数来检查这一点。你知道这个正则表达式吗。

检查哪里有2个后续换行符(新章节),在最后一次遇到2个后续的换行符后,在文件结束前检查包含文本的多行文本。

这里有一个不使用regexp的答案。

$text = <<<EOF
Hello this is test     
Test This is also Test.
Text:12563
This is test
EOF;
$paras = explode("'n'n", $text);
$last = $paras[(count($paras) - 1)];
$needle = "Text:12563";
if (strpos($last, $needle)) {
    echo "Found";
}