str = 'foo myfoo http://t...content-available-to-author-only...r.com/food is awesome';
str = str.replace(/\bfoo\b/g, 'bar');
while (/http:\/\/[^\s]*?foo/.test(str))
str = str.replace(/(http:\/\/[^\s]*?)?foo/g, function($0, $1) {
return $1 ? $1 + 'bar' : $0;
});
print(str);
c3RyID0gJ2ZvbyBteWZvbyBodHRwOi8vdC4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4uci5jb20vZm9vZCBpcyBhd2Vzb21lJzsKc3RyID0gc3RyLnJlcGxhY2UoL1xiZm9vXGIvZywgJ2JhcicpOwp3aGlsZSAoL2h0dHA6XC9cL1teXHNdKj9mb28vLnRlc3Qoc3RyKSkKICAgIHN0ciA9IHN0ci5yZXBsYWNlKC8oaHR0cDpcL1wvW15cc10qPyk/Zm9vL2csIGZ1bmN0aW9uKCQwLCAkMSkgewogICAgICAgIHJldHVybiAkMSA/ICQxICsgJ2JhcicgOiAkMDsKICAgIH0pOwpwcmludChzdHIpOwo=