日期:2014-05-16  浏览次数:20299 次

这个是prototype.js的字符模板类 问个问题
var   Template   =   Class.create();
Template.Pattern   =   /(^|.|\r|\n)(#\{(.*?)\})/;
Template.prototype   =   {
    initialize:   function(template,   pattern)   {
        this.template   =   template.toString();
        this.pattern     =   pattern   ||   Template.Pattern;
    },

    evaluate:   function(object)   {
        return   this.template.gsub(this.pattern,   function(match)   {
            var   before   =   match[1];
            if   (before   ==   '\\ ')   return   match[2];
            return   before   +   String.interpret(object[match[3]]);
        });
    }
}


这个正则/(^|.|\r|\n)(#\{(.*?)\})/
中(^|.|\r|\n)是匹配什么的呢
before   ==   '\\ '这个又是什么意思

------解决方案--------------------
中(^|.|\r|\n)是匹配什么的呢
before == '\\ '这个又是什么意思
======================================
(^|.|\r|\n)匹配开头或者所有单个字符。
before == '\\ '
如果before等于\则返回true否则返回false(第一个\为转移符)