Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 下划线.template的uu.templateSettings的正确胡须模板配置是什么?_Javascript_Regex_Underscore.js_Mustache - Fatal编程技术网

Javascript 下划线.template的uu.templateSettings的正确胡须模板配置是什么?

Javascript 下划线.template的uu.templateSettings的正确胡须模板配置是什么?,javascript,regex,underscore.js,mustache,Javascript,Regex,Underscore.js,Mustache,我到处找了找,找不到一个真正有效的 在小胡子中,当你扔掉2个卷发时,里面的线将被逃脱,如果你扔掉3个卷发,则不会 // when you pass {foo: '"bar"'} as hash, the following template will be: {{foo}} // => "bar" {{{foo}}} // => "bar" 对吧??因此,我创建了以下内容 这显示了插值和转义相反,即2卷曲表示未转义,3卷曲表示转义。当我在

我到处找了找,找不到一个真正有效的

在小胡子中,当你扔掉2个卷发时,里面的线将被逃脱,如果你扔掉3个卷发,则不会

// when you pass {foo: '"bar"'} as hash, the following template will be: 
 {{foo}}  // => "bar"
{{{foo}}} // => "bar"
对吧??因此,我创建了以下内容

这显示了插值和转义相反,即2卷曲表示未转义,3卷曲表示转义。当我在
.templateSettings
中的
escape
interpolate
之间切换时,它就是不起作用。为什么?下划线模板优先于这三种模板(
escape
interpolate
evaluate


我知道我现在忽略了jsfiddle上的
evaluate
,如果这两者一起工作,那就太棒了,但现在,我想让2和3卷曲工作得很好…

搜索转义的正则表达式,然后插值,然后求值。这就是为什么转义表单<{}}在未转义表单{{}}之前匹配。您可以自己在源代码中更改
\uuu.template
的顺序

var matcher = new RegExp([
  (settings.escape || noMatch).source,
  (settings.interpolate || noMatch).source,
  (settings.evaluate || noMatch).source
].join('|') + '|$', 'g');
更改上述行的顺序将更改优先级

如果不想更改下划线优先级,可以使用更复杂的转义正则表达式。要做到不回头看是很困难的,但我想到了:

/\{\{([^\{\}]+?)(?!\}\}\})\}\}/

这意味着:
{{
,后跟一个或多个非大括号字符,后面不应跟三大括号(
}}
),后跟双大括号
}
。它在你的小提琴上起作用,希望能对你起作用。

你在
下划线.js:1151
中得到一个
未损坏的语法错误:意外标记)
。可能是一只虫子;连接JavaScript字符串并尝试对其求值。那似乎管用。令人惊叹的!