regexgruntjsgrunt-contrib-copy

grunt contrib copy and replace text in file using RegEx


I have a grunt contrib copy task that will copy a file correctly, but I would also like to change a file path that is repeated through out the the content of the file that is being copied. I do not have a lot of experience with javascript regular expressions, my only success so far is replacing one word with another word.

options: {
    process: function (content, srcpath) {
        return content.replace((/...\/resources\/fonts//gi,""));
    }
}

I would like to replace the string "../resources/fonts" with an empty string "".


Solution

  • If you want to replace "../resources/fonts" then the regexp you need is:

    /\.\.\/resources\/fonts/gi
    

    (escape the dots and slashes)