function transformURL(a) { a = a.replace(/^www\.|http:\/\/www\.|^\/\/www\./,''); return a = ('http://'+a); } var b = 'mysite.ru'; alert(transformURL(b)) var b1 = 'www.mysite.ru'; alert(transformURL(b1))