在繁重的字符串替换正则表达式问题 - Regex issue in Grunt string replace

- 此内容更新于:2015-12-20
主题:

这不是替换文本。这是代码:如果我写下描述内容手动,它被替换为变量的内容。

原文:

Somehow this is not replacing my text. Here is the code:

pattern: '<meta name="description" content="/(.*)/i" />',
replacement: '<meta name="description" content="<%= clientAppMetaDataDescription %>" />'

If I write down description content manually, it is replaced with variable content.

网友:你用什么,或者别的什么?

(原文:What are you using grunt-string-replace, grunt-regex-replace or something else?)

楼主:

(原文:grunt-string-replace)

网友:我猜没有定义,你可以试着用你也可以添加一些调试功能检查价值。

(原文:I'm guessing clientAppMetaDataDescription is not defined, you could try using replacement: function (match, p1) { return /* whatever value */; } you could also add some debugging to the function to check the value.)

网友:至于正则表达式,修饰符是无用的,没有符号模式中,有不同的情况下。此外,使用模式可能匹配一个空字符串替换函数是充满了不必要的副作用。所以,试着(或者如果需要正则表达式分隔符)。

(原文:As for the regex, the i modifier is useless as there are no symbols that have different cases in the pattern. Moreover, using a pattern that may match an empty string in a replace function is fraught with unwanted side effects. So, try .+ (or /.+/ if regex delimiters are required).)