1

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

rene
  • 41,474
  • 78
  • 114
  • 152
user3221374
  • 13
  • 1
  • 3

2 Answers2

2

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

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

(escape the dots and slashes)

Lesmana
  • 25,663
  • 9
  • 82
  • 87
Mangled Deutz
  • 11,384
  • 6
  • 39
  • 35
0

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'
        }
      ]
    },
  },
Kushal Jayswal
  • 925
  • 1
  • 12
  • 31