let getStrinsBetweenTwoStrings = (targetString, beginString, endString) => {标签:aa,getStrinsBetweenTwoStrings,JS,re,beginString,let,数组,字符串 From: https://blog.51cto.com/u_15920212/5962650
let aa = targetString.split(beginString), re = [];
for (let i = 1, len = aa.length; i < len; i++) {
let a = aa[i],s = a.split(endString)[0];
s && re.push(s);
}
return re;
};
//测试----------------------------------------
console.log(getStrinsBetweenTwoStrings("一[句话]里面[有]很[多个]方[括号]", "[", "]"));
//[ '句话', '有', '多个', '括号' ]
console.log(getStrinsBetweenTwoStrings("我◆◆和我❤❤❤的祖国,◆◆一刻❤❤❤也◆◆不能❤❤❤◆◆分割❤❤❤,无论我走到哪里,都流出◆◆一首赞歌❤❤❤", "◆", "❤❤"));
//[ '和我', '一刻', '不能', '分割', '一首赞歌' ]