只从数组(RegEx和PHP)获取内部链接和外部链接


Get only internal links and external from array (RegEx and PHP)

这是我的数组输出:

Array
(
    [0] => http://www.example.com/some-page/
    [1] => http://www.example.com/another-page/
    [2] => http://www.example.com/third-page/
    [3] => https://www.example.com/ssl/
    [4] => https://www.example.com/with-slash-at-the-end/
    [5] => https://www.example.com/without-slash-at-the-end
    [6] => /internal-link
    [7] => /anther-internal-link/
    [8] => https://www.my-own-domain.com/internal-link-too-but-with-absolute-path/
)

如何从该数组中只获取外部链接和内部链接?我不在乎哪一个。

此正则表达式似乎可以很好地查找internal link

(.*my-own-domain'.com.*)|(^'/.*$)

Regex演示

PHP代码

$re = "/(?:.*my-own-domain''.com.*)|(?:^''/.*$)/m";
foreach($str as $x) {
   if (preg_match($re, $x)) {
      echo $x . "" . "'n";
   }
}

Ideone演示