美文网首页
正则表达式匹配

正则表达式匹配

作者: Bookish倩宝 | 来源:发表于2016-10-19 17:17 被阅读0次
    屏幕快照 2016-10-09 20.24.58.png
    function result(tpl,data){
      var pattern = /{\\w+}/g;
      var matches = pattern.exec(tpl);
      var desc =tpl.replace(pattern,"%s");
      console.log(desc,data.name,data.age,data.city);
    }
    
    var data1={name:'abc',city:'cheng',age:"dd"}
    var desc = "我是{name},今年{age},来自{city}"
    result(desc,data1);
    

    相关文章

      网友评论

          本文标题:正则表达式匹配

          本文链接:https://www.haomeiwen.com/subject/uwuuyttx.html