使用 regexr.com 我的正则表达式可以工作,但 php 中的 preg_match 返回 null。
在几个 php 测试器中尝试了很多次。
正则表达式是:
/Donor Comment:\*(.*?)\*/
文字是:
United States* > Donor Comment:*Thx Barbara for your wonderful offerings, and thx to > CVRAN for the essential support you provide to asylum seekers and for > the creative fundraising via an Arts Marathon!*
适用于正则表达式
PHP 是:
preg_match('/Donor Comment:\*(.*?)\*/', $msg, $donor_comment);
Preg_match 返回 null
如果您使用 PHP 的 Regexr,我建议将 Regex 引擎更改为 PCRE。
函数
preg_match
返回一个bool|int值,如果你想打印结果,这里是一个例子。
$msg = "United States* > Donor Comment:*Thx Barbara for your wonderful offerings, and thx to > CVRAN for the essential support you provide to asylum seekers and for > the creative fundraising via an Arts Marathon!* ";
preg_match('/Donor Comment:\*(.*?)\*/', $msg, $matches);
print_r($matches[1]); // Thx Barbara for your wonderful offerings, and thx to > CVRAN for the essential support you provide to asylum seekers and for > the creative fundraising via an Arts Marathon!