var str = `text text text id 34355 text text id 35235 text text id 45346`; str = str.replace(/(id\s\d+)[\S\s]*?id\s45346/img, '$1'); alert(str);