Question

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 "".

Était-ce utile?

La solution

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

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

(escape the dots and slashes)

Autres conseils

Suggested code is not working with my code below. However, regex seems correct.

copy: {
    main: {
      options: {
          process: function (content, srcpath) {
              return content.replace((/dist\//gi,""));
          }
      },
      files: [
        {
          expand: true,
          src: ['*.html'],
          dest: '<%= distDir %>/',
          filter: 'isFile'
        }
      ]
    },
  },
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top