基本上我正在使用 bash shell 脚本cat new | sed '/1. /,/<div/!d' > new2
来提取从 1. 
开始并在第一次出现<div
时结束的文本。然后将其保存到 new2 文件中。如何使用 pcre 在 php 中完成相同的工作。
$text = file_get_contents('php://stdin');
$matches = array();
if(preg_match('/1'. (.*?)<div/', $text, $matches)) {
echo $matches[1];
}
测试:
echo 'abc 1. This is a test<div>more stuff<div>and more' | php test.php
;This is a test