Building a regex is an expensive operation that you should do once. You can then use that regex as many times as you need, and it will likely outperform php in replacing all the captures.
So measure the replace_all
called many times using the same regex. (On possibly different inputs)