为什么我的正则表达式 return 在捕获子模式中为空?

Why does my regex return empty in the capturing subpattern?

我已经编写了这些代码来将类似 url 的文本转换为超链接:

$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/www\.[a-zA-Z0-9]{5}\.com(\w*)(\/\S*)?/";
echo preg_replace($reg_exUrl, '<a href="://www..com">://www..com</a>','http://www.abcde.com/index.html');

输出为:

<a href="http://www..com">http://www..com/index.html</a>

但是 $2 是空的 - 这是为什么?

我想你想要这样的东西:

(http|https|ftp|ftps)\:\/\/www\.([a-zA-Z0-9]{5})\.com(\w*\/\S*)?

https://regex101.com/r/MJ3A6K/1