js正则replace

reg = /{{#account}}(.*){{\/account}}/g

bao.replace(reg, function(bao,baobao){
  return baobao;
})
"Your account is {{a}} "
bao = "{{#account}}Your account is {{a}} {{/account}}"

replace第二个参数可以是字符串也可以是function,

若为字符串则替换第一个参数匹配的字符串;

若为function,则function中第一个参数表示replace第一个参数的完全匹配,function的第二个参数表示replace第一个参数的不完全匹配(即取得其小括号中的字符串)

posted @ 2015-01-27 09:50  way~  阅读(149)  评论(0编辑  收藏  举报