var str = '123 <img src="/image/fisker-tesla-header-650x0.jpg"> 456'; str = str.replace(/(<img\s+[^>]*\ssrc=["'])(....[^:]{2}[^"']*['"][^>]*>)/g, "$1http://icdn6.digitaltrends.com$2"); alert(str);