我想匹配自定义字符串之间的所有字符串,所以我们在这里:
var string = `
<!--@hello-dear:John-->
<h1>John</h1>
<!--@bye-dear:John-->
`;
var startString = "<!--@hello-dear:John-->";
var endString = "<!--@bye-dear:John-->";
var regString = startString + "(.*?)" + endString;
var regex = new RegExp(regString, "i");
console.log(string.match(regex));
返回 null
预计将对象与字符串
匹配"<!--@hello-dear:John-->
<h1>John</h1>
<!--@bye-dear:John-->"