php preg_replace kills cpu
Simple as that:

/&lt;script&gt;[^&lt;]*?googletagmanager\.com.*?&lt;\/script&gt;/s


What's killing performance for you, is most likely the backtracking followed by a look-ahead on the first padding. Using a character class instead of a look-ahead, and making it non-greedy should solve that issue.

The /s modifier allows you to use . instead of explicit [\s\S].