var varka = "... <div id='imdiv'>text text text</div> ..."; alert(varka.replace(/[^]*<div id='imdiv'>([^]*)<\/div>[^]*/, "$1")) // text text text