-->

在咕噜-contrib请复制的“进程”选项使用正则表达式不工作(Using Regex in gru

2019-11-03 08:57发布

我试图使用动态咕噜的副本插件从我的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问题或与我的正则表达式。 有什么建议么?

Answer 1:

您的选择是在错误的地方,他们需要的是一个级别更高:

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, " ");
                }
            }


文章来源: Using Regex in grunt-contrib-copy's “process” option not working