سؤال

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

هل كانت مفيدة؟

المحلول

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

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

(escape the dots and slashes)

نصائح أخرى

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'
        }
      ]
    },
  },
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top