Adding keywords at specific places in a string using javascript

I am writing a code to create a new string from a predefined string by adding some keywords at particular places in the original string i was trying the indexOf() feature to achieve this but unable to complete the work

for eg. if my string is

now i want to add some keywords to this string at specific places to make the final string as

https://goo.google.co.in/goo/webhp?source=search_app

here i have replaced ‘www’ by ‘goo’ and alos added ‘goo’ between the ‘.in/webhp’ as ‘.in/goo/webhp’

Use a regular expression to specify the various patterns in the content and what they are to be replaced with.

What i have tried is like

var flip;
    flip=subdomain.indexOf(".com") 
    flip=flip+3;
    subdomain=subdomain.substr(flip)
   var res=http://goo.google.com/goo

    if(subdomain.indexOf("?") == -1){
         var res ='http://goo.google.com/goo'+subdomain + '?yahoo';
    }else{
        if(subdomain.indexOf("&") == -1)
       {
         var res ='http://goo.google.com/goo'+ subdomain + '&yahoo';
        }else{
            subdomain=subdomain.substring( 0, subdomain.indexOf( "&" ) );
            var res = 'http://goo.google.com/goo'+ subdomain + '&yahoo';
        }
    }      
});

but this is not working to generate the final string any suggetions

To do that conversion (replacing www wit goo and adding /goo) to any address containing google.co.in you can do the following

flip = 'https://www.google.co.in/webhp?source=search_app';
re = /^(.*?\/\/).*?(\.google\.co\.in)(\/.*)$/;
flip = flip.replace(re, '$1goo$2/goo$3');