let str = <span><%=name%></span>;
let reg = /<%=(\w+)%>/; //注意:\w表示任意合法字符;+表示任意次
let res = reg.exec(str);//注意:这个方法只能匹配一次
let a = res[0]; //<%=name%>
let b = res[1]; //name
如果需要全部找出来
let obj = {
age : 10,
name:'sun'
}
let str = '<span><%=name%></span><span><%=age%></span>';
let reg = /<%=(\w+)%>/;
let res ;
while(res = reg.exec(str)){
let key = res[1];
let change = res[0];
let value = obj[key];
str = str.replace(change,value)
}