var pattern = /(?<=wpf).*?(?=wpd)/, str = 'wpf123234344wpd'; console.log(str.match(pattern)); console.log(str.replace(`wpf${str.match(pattern)[0]}wpd`,'22'))