var str = 'abcsdldkfvxyzsdlfabcvkdfxyzasdfvabcsdvxyzdf' str = str.replace(/(abc)[\s\S]+?(xyz)/g, '$1$2'); alert(str);