我想在 PHP 中使用 perl reqexp。
例如,
珀尔:
$url =~ qr{https?://([^\/\?&:#]+\.)?example.com};
PHP:
preg_match("/https?:\/\/([^\/\?&:#]+\.)?example\.com/", $url);
You answered your own question? preg_match
is able to process virtually all of Perl regex syntax. (The "p" is for "Perl".)
Learn more about PHP preg_match
in its documentation.
您使用了正确的功能preg_match
。现在关于比赛的捕获,您需要传递另一个参数:
preg_match("/https?:\/\/([^\/\?&:#]+\.)?example\.com/", $url, $match);
比赛将在$match[1]
.