JSFiddle - React, Tailwind, and code Playground

HTML

<script>
    function test() {
        var text = 'www.dom1.com?www.dom2.net';
    
    // uncomment to test www.dom2.net as cgi parameter
    //text = 'www.dom1.com/bin?www.dom2.net';

    // so, i think, need detect end of URL with '?' only if no one '/' in that url
    // and pass ? if it used as url (not really question)

        var r = /(^|[\s\?])(www\..+?(?=([\s]|\?|($))))/g;

    
        var res = text.replace(r, '$1<a href="$2">$2</a>');

        document.getElementById('b').innerHTML = res;
    }
</script>
<div id="b">...</div>
<br>
<div onclick="test();">click</div>