正则表达式 从模式中跳过消息


Regular expression Skip message to,from patterns

我在 php 中有这个字符串,我想跳过模式

------------------------------------------
FROM:Andy;
SENT:Mon, Jun 18 2012 1:52pm
TO:Ali;
------------------------------------------
FROM:Ali;
SENT:Mon, Jun 18 2012 12:26pm
TO:Andy;
Some message text here

我想使用正则表达式跳过前两种模式并仅返回"某些消息文本..."以上两种模式可以更多。在 PHP 中

要 100% 确定您没问题,请使用模式/^.*'nSENT:[^'n]*'nTO:[^'n]*'n'n(.*)$/is

在此处查看并测试代码。


如果您在最后一个"TO:"行之后的空行中可能有一些空格字符,请使用正则表达式/^.*'nSENT:[^'n]*'nTO:[^'n]*'n's*'n(.*)$/is

.*TO:.*;'s*(.*)

确保设置点匹配换行符

在 php (preg) 中,这变成了

if (preg_match('/.*TO:.*;'s*(.*)/s', $subject, $regs)) {
    $result = $regs[1];
} else {
    $result = "";
}