Do you need that?
/(?<!https:\/\/)(?<!http:\/\/)(www\.[\w-.]*?[\w-]+?(\/[\w-]*?)*?)((?=[^\w.\/-]+?)|$)+/ig
You can have a look here:
https://regex101.com/r/XvmR4V/4
If you have a large String that contains website names, this regex matches all names, that do not start with "http://" or "https://". Your websites names always have to start with "www"!!!
Without lookaheads and lookbehinds you can try this.
You are going to find the results in the 2. Group ($2).
/([^\/]{2,2})(www\.[\w-.]*?[\w-]+?(\/[\w-]*?)*?)(([^\w.\/-]+?)|$)+/ig
https://regex101.com/r/XvmR4V/5
Now even for www.google.de:
([^\/]{2,2}|^)(www\.[\w-.]*?[\w-]+?(\/[\w-]*?)*?)(([^\w.\/-]+?)|$)+
https://regex101.com/r/XvmR4V/6
You can replace like that.
I replaced the 'www...' with 'Test'.
/([^\/]{2,2}|^)(www\.[\w-.]*?[\w-]+?(\/[\w-]*?)*?)(([^\w.\/-]+?)|$)+/$1Test$4/gi
I testet it with the regex-Tool from IntelliJ.
My input was:
<p><a href="https://www.w3schools.com/html/"><a href="http://www.w3schools.com/html/">www.w3schools.com</a></p>
<p><a href="https://www.google.com/html/"><a href="http://www.google.com/html/">www.google.com</a>
The output was:
<p><a href="https://www.w3schools.com/html/"><a href="http://www.w3schools.com/html/">Test</a></p>
<p><a href="https://www.google.com/html/"><a href="http://www.google.com/html/">Test</a>
If it helps, it would be greate if you vote it up :-)