正则表达式在正则表达式中工作,但在 php preg_match 中不返回任何内容

问题描述 投票:0回答:1

使用 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 regex preg-replace
1个回答
0
投票

如果您使用 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!
© www.soinside.com 2019 - 2024. All rights reserved.