Replacing strings using grunt-replace

I would like to replace the string url("images/

with some other string, eg. ZZZZZZZZZZZZ

using grunt-replace.

I am using the following configuration:

replace: {
    dist: {
        options: {
            patterns: [
                {
                    match: /"/g,
                    replacement: 'ZZZZZZZZZZZZ'
                }
            ]
        },
        files: [
            {
             expand: true, flatten: true, 
             src: ['dist/app/css/app.css'], dest: 'dist/app/css2/'
            }
        ]
    }
}

      

I tried match: /"/g

and /images/g

and both were replaced, but neither worked:

  • match : /"images/g

  • match : /\"images/g

  • match : /("images)/g

    // worked when testing http://regex101.com/r/tU5iM3/2
  • match : /(\"images)/g

    // worked when tested at http://regex101.com/r/tU5iM3/3

What am I missing here?

UPDATE I added a section of files

my example with the xunt-replace + working setting /images/g

. I am using some other Grunt tasks and the Grunt replacement is the last one:

grunt.registerTask('default', ['useminPrepare', 'copy', 'concat', 'uglify', 'cssmin', 'usemin', 'replace']);

      

But I don't see how this can break my regex. I am testing my configuration by running the command: grunt -v --stack && grep -R "ZZZZZZZZZZZZ" .

+3


source to share


1 answer


First, regex101 references point to code using the Python regex library, not JavaScript, which is what Grunt uses. Then characters (

and \

have to be escaped, but none of them work. The regex you're looking for is:

/url\("images\//g

      



(see https://regex101.com/r/aY9hY0/1 to play with it)

0


source







All Articles