let theArr = `<p> </p>
<p>123<img src="http://10.10.0.99:8000/api/file/getFile/news/top.png" alt="" width="200" height="200" /><a title="004.xlsx" href="theoryOfLearning/004.pdf">theoryOfLearning/004.pdf</a></p>`
// console.log(theArr)
theArr = "111000222"
function getInnerString(source, prefix, postfix) {
let regexp = new RegExp(encodeReg(prefix) + '.+' + encodeReg(postfix), 'gi');
let matches = String(source).match(regexp);
let tppArr = matches[0]
tppArr = tppArr.replace(prefix, "")
tppArr = tppArr.replace(postfix, "")
return tppArr
}
//转义影响正则的字符
function encodeReg(source) {
return String(source).replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1');
}
let result = getInnerString(theArr, "111", "222")
// 拿到中间的字符串
console.log(result)
网友评论