在grunt-contrib-copy"过程中使用Regex"选项不起作用

时间:2014-10-04 06:51:12

标签: javascript regex gruntjs grunt-contrib-copy

我正在尝试使用Grunt的复制插件动态删除我的index.html文件中的实时重装脚本。

我的Gruntfile中包含相关代码的部分在这里:

copy: {
            main: {
                files: [
                {
                    expand: true, 
                    src: 'index.html',
                    dest: 'build/',
                    options: {
                        process: function (content, srcpath){
                            return content.replace(/<script src = "http:\/\/localhost:9090\/livereload.js"><\/script>/g, " ");
                        }
                    }
                },

我检查了一个正则表达式测试程序,它显示我上面的正则表达式应与我的html中的脚本匹配。

虽然正则表达式测试人员认为它是合法的,但我之前的匹配结果不准确,所以我需要帮助确定我的Gruntfile或我的正则表达式是否存在问题。有什么建议吗?

1 个答案:

答案 0 :(得分:2)

你的选择在错误的地方,他们需要更高一级:

copy: {
        main: {
            files: [
            {
                expand: true, 
                src: 'index.html',
                dest: 'build/'
            },
            options: {
                process: function (content, srcpath){
                    return content.replace(/<script src = "http:\/\/localhost:9090\/livereload.js"><\/script>/g, " ");
                }
            }