Php $matches在preg_match_all中返回相同的值

Php $matches在preg_match_all中返回相同的值,php,regex,Php,Regex,我有一系列的链接,我尝试使用preg\u match\u all,regex进行匹配,但每次都给我相同的结果 foreach($result[0]作为$temp){ preg_match_all($regex1,$temp[“content”],$matches); $storeUrl[]=$matches; } foreach($storeUrl作为$tem){ preg_match_all($regex2、$tem[]、$matches); $storeUrllist[$count1++]=

我有一系列的链接,我尝试使用
preg\u match\u all,regex进行匹配,但每次都给我相同的结果

foreach($result[0]作为$temp){
preg_match_all($regex1,$temp[“content”],$matches);
$storeUrl[]=$matches;
}
foreach($storeUrl作为$tem){
preg_match_all($regex2、$tem[]、$matches);
$storeUrllist[$count1++]=$matches;
}

$matches
对第一个foreach和第二个foreach都很好,它总是只返回相同的输出,即使它不匹配

我猜您可能想要设计一个类似于以下内容的表达式:

\b(?:https?:\/\/)?(?:www\.)?\w+\.(?:org|org2|com)\b
或:

或:

不过我不确定

试验 输出
如果您想探索/简化/修改该表达式,请在的右上面板上进行解释。在中,您可以查看它与一些示例输入的匹配情况(如果您愿意)。

我猜您可能希望设计一个类似于以下内容的表达式:

\b(?:https?:\/\/)?(?:www\.)?\w+\.(?:org|org2|com)\b
或:

或:

不过我不确定

试验 输出
如果您希望探索/简化/修改该表达式,可以在的右上面板上对其进行解释。在中,如果您愿意,可以查看它与一些示例输入的匹配情况。

需要查看
$storeUrl
$regex2
@tim感谢您的回复,$regex2=/^\b\w{5}+[:\/\/\]+\w+\.+\w+。+\w+。(org | org2 | com)\$storeurl是一个包含大量链接的数组,让我们看一个链接,当我在代码中测试时,它工作正常,但在代码中$matches只返回相同的数据
$tem[]
应该是
$tem
我也尝试过这个选项@tim需要查看
$storeurl
$regex2
@tim感谢回复,$regex2=/\b\w{5}+[:\/]+\w+\.+\w+。(org | org2 | com)\b/和$storeurl是一个包含巨大链接的数组,让我们拿一个链接来说,当我在代码中测试时它工作正常,但在代码中$matches只返回相同的数据
$tem[]
应该是
$tem
我也尝试了@timThank,上面三个regexp也将返回域,你能帮我建立一个正则表达式,它会检查子域是否存在,如果它包含,那么只需要给出结果示例:它包含子域,所以预期的结果是,让我们采取另一种情况,在这种情况下,不需要返回任何东西。很多,上面三个正则表达式也会返回域,请您帮助形成一个正则表达式,它将检查子域是否存在,如果它包含,则只需给出结果示例:它包含子域,因此预期结果是,让我们采取其他方案在这种情况下无需返回任何内容
\b(?:https?:\/\/)(?:www\.)\w+\.(?:org|org2|com)\b
$re = '/\b(?:https?:\/\/)?(?:www\.)?\w+\.(?:org|org2|com)\b/m';
$str = 'some content http://alice.com or https://bob.org or https://www.foo.com or or baz.org2 ';

preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);

var_dump($matches);
array(4) {
  [0]=>
  array(1) {
    [0]=>
    string(16) "http://alice.com"
  }
  [1]=>
  array(1) {
    [0]=>
    string(15) "https://bob.org"
  }
  [2]=>
  array(1) {
    [0]=>
    string(19) "https://www.foo.com"
  }
  [3]=>
  array(1) {
    [0]=>
    string(8) "baz.org2"
  }
}