5

我想在 PHP 中使用 perl reqexp。

例如,

珀尔:

$url =~ qr{https?://([^\/\?&:#]+\.)?example.com};

PHP:

preg_match("/https?:\/\/([^\/\?&:#]+\.)?example\.com/", $url);
4

2 回答 2

7

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.

于 2012-11-07T09:09:51.873 回答
1

您使用了正确的功能preg_match。现在关于比赛的捕获,您需要传递另一个参数:

preg_match("/https?:\/\/([^\/\?&:#]+\.)?example\.com/", $url, $match);

比赛将在$match[1].

于 2012-11-07T09:11:55.983 回答