为什么这个正则表达式清除javascript文件

I have this code:

$tags = implode("|", array("a", "script", "link", "iframe", "img", "object"));
$attrs = implode("|", array("href", "src", "data"));
$any_tag = "\w+(?:\s*=\s*[\"'][^\"']*[\"'])?";
$replace = array(
    "/(<(?:$tags)(?:\s*$any_tag)*\s*(?:$attrs)=[\"'])(?![\"']?(?:data:|#))([^'\"]+)([\"'][^>]*>)/" => function($match) {
        return $match[1] . $match[2] . $match[3]; // return same data
    }
);
$page = preg_replace_callback_array($replace, $page);
echo $page;

and I'm runing this code against https://duckduckgo.com/d2038.js and $page is empty after executing replace, why? If I've added print_r($match); in callback I've got:

Array
(
    [0] => <a href='/a'>
    [1] => <a href='
    [2] => /a
    [3] => '>
)

the same happen if I assign the value of replace to another variable. Why the page is empty?

If I runing this in regex101 it match more elements https://regex101.com/r/CPGuKd/1 and it don't clear the output.

The final cooked regex from within your code is this:

(<(?:a|script|link|iframe|img|object)(?:\s*\w+(?:\s*=\s*["'][^"']*["'])?)*\s*(?:href|src|data)=["'])(?!["']?(?:data:|#))([^'"]+)(["'][^>]*>)

which is different from your live demo and causes a catastrophic backtracking.

According to your live demo there should be a little change in PHP code:

"/(<(?:$tags)(?:\s*$$any_tag)*...
                   ^