var string = 'xxx blabla sfdsfs blabla'; var processed = string.replace(new RegExp('blabla', 'img'), '<img src="img.png" />'); alert(processed);