Replacing strings using grunt-replace

Disper

I would like to replace url("images/ string to some other string e.g. ZZZZZZZZZZZZ using grunt-replace.

I use 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've tried match: /"/g and /images/g and both of them were replaced, but none of those worked:

What am I missing here?

UPDATE I've added files section of my grunt-replace configuration + working /images/g example. I'm using some other Grunt tasks and Grunt replace is last one:

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

But I don't see how it it could break my regex replace. I'm testing my configuration by running command: grunt -v --stack && grep -R "ZZZZZZZZZZZZ" .

Joe Hildebrand

First off, your regex101 links point to code using the Python regex library, rather than JavaScript, which is what Grunt uses. Next, the ( and \ characters need to be escaped, but none of the others do. The regexp you're looking for is:

/url\("images\//g

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Replacing substrings with Strings not using replace()

From Dev

Replacing multiple strings using str_replace not working

From Dev

Replacing a HTML tag with Grunt-Replace

From Dev

replacing strings with Regex.Replace()

From Dev

Replace command condition for replacing strings

From Dev

Using Grunt to Replace Text in a File

From Dev

Using Grunt to Replace Text in a File

From Dev

Replacing strings in Typescript file with gulp-replace

From Dev

R - replacing strings using gsub()

From Dev

grunt: how to replace paths in html file using grunt task

From Dev

grunt: how to replace paths in html file using grunt task

From Dev

Using Grunt to preprocess and replace environment variables

From Dev

Replacing strings like {{Asd}} using RegEx

From Dev

Replacing strings one by one using javascript

From Dev

Replacing Strings using Maven in Java Annotations

From Dev

Replacing a consecutive single and double quote using .replace?

From Dev

Using REPLACE in MySQL is not actually replacing row

From Dev

replacing an email address using regex.replace

From Dev

javascript replace() not replacing text containing literal \r\n strings

From Dev

javascript replace() not replacing text containing literal \r\n strings

From Dev

Replacing variables with grunt

From Dev

Replacing variables with grunt

From Dev

Replace strings using List Comprehensions

From Dev

Replacing strings with strings in Java

From Dev

Replacing text in Grunt Template String

From Dev

Replacing text in line, with different strings using shell script

From Dev

Replacing text in line, with different strings using shell script

From Dev

Replacing strings in file, using patterns from another file

From Dev

Replacing multiple text strings in blocks of text using jquery.each()

Related Related

  1. 1

    Replacing substrings with Strings not using replace()

  2. 2

    Replacing multiple strings using str_replace not working

  3. 3

    Replacing a HTML tag with Grunt-Replace

  4. 4

    replacing strings with Regex.Replace()

  5. 5

    Replace command condition for replacing strings

  6. 6

    Using Grunt to Replace Text in a File

  7. 7

    Using Grunt to Replace Text in a File

  8. 8

    Replacing strings in Typescript file with gulp-replace

  9. 9

    R - replacing strings using gsub()

  10. 10

    grunt: how to replace paths in html file using grunt task

  11. 11

    grunt: how to replace paths in html file using grunt task

  12. 12

    Using Grunt to preprocess and replace environment variables

  13. 13

    Replacing strings like {{Asd}} using RegEx

  14. 14

    Replacing strings one by one using javascript

  15. 15

    Replacing Strings using Maven in Java Annotations

  16. 16

    Replacing a consecutive single and double quote using .replace?

  17. 17

    Using REPLACE in MySQL is not actually replacing row

  18. 18

    replacing an email address using regex.replace

  19. 19

    javascript replace() not replacing text containing literal \r\n strings

  20. 20

    javascript replace() not replacing text containing literal \r\n strings

  21. 21

    Replacing variables with grunt

  22. 22

    Replacing variables with grunt

  23. 23

    Replace strings using List Comprehensions

  24. 24

    Replacing strings with strings in Java

  25. 25

    Replacing text in Grunt Template String

  26. 26

    Replacing text in line, with different strings using shell script

  27. 27

    Replacing text in line, with different strings using shell script

  28. 28

    Replacing strings in file, using patterns from another file

  29. 29

    Replacing multiple text strings in blocks of text using jquery.each()

HotTag

Archive