!DOCTYPE htmlhtml head meta charset=UTF-8 titletitle head body script var str=div枝上柳绵吹又少many 岁数是age 性别是sexdiv var pattern=a-zA-Z+ 第一次匹配 var result=patternexecstr consolelogresult str=st
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
var str='<div>枝上柳绵吹又少{{many}} 岁数是{{age}} 性别是{{sex}}</div>'
var pattern=/{{([a-zA-Z]+)}}/
var result = pattern.exec(str);
while(result){
str=str.replace(result[0],result[1]);
console.log(str);
result = pattern.exec(str);
}
</script>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/eQEP 著作权归作者所有。请勿转载和采集!