要从word到文件结尾删除的php正则表达式

要从word到文件结尾删除的php正则表达式,php,regex,preg-replace,Php,Regex,Preg Replace,在php中,我需要一个正则表达式,使用preg\u replace()函数从特定单词到文件末尾进行删除 例如,文件可能类似于: Hi, I'm Stefy, this is my friend: <div id="friend">Mr. Brown</div>. 有人能帮我吗?你可以在这里使用DOTALL修饰符 (?s)is\s+my\s+friend:.*$ 用空字符串替换匹配的字符将获得所需的输出 (?s)is\s+my\s+friend:.*$ <?p

在php中,我需要一个正则表达式,使用
preg\u replace()
函数从特定单词到文件末尾进行删除

例如,文件可能类似于:

Hi, I'm Stefy,
this is my friend:
<div id="friend">Mr. Brown</div>.

有人能帮我吗?

你可以在这里使用DOTALL修饰符

(?s)is\s+my\s+friend:.*$
用空字符串替换匹配的字符将获得所需的输出

(?s)is\s+my\s+friend:.*$
<?php
$string =<<<EOT
Hi, I'm Stefy,
this is my friend:
<div id="friend">Mr. Brown</div>.
EOT;
$pattern = "~(?s)is\s+my\s+friend:.*$~";
$replacement = "";
echo preg_replace($pattern, $replacement, $string);
?>
Hi, I'm Stefy,
this