BBaysinger
BBaysinger

Reputation: 6987

Regular expressions not working in gulp-regex-replace?

I'm trying to remove all line breaks in an HTML file using gulp-regex-replace. I'm trying the regular expressions from here. None of them work.

let replace = require('gulp-regex-replace');

gulp.task("strip", function () {
  return (
    gulp
      .src("./*.html")
      .pipe(replace({regex:/\r?\n|\r/g, replace:''}))
      .pipe(gulp.dest("./dist/"))
  );
});

I also tried /[\r\n]+/gm with no luck.

Trying other regular expressions works, but line breaks don't budge. I'm using OS X with VSCode.

Upvotes: 1

Views: 145

Answers (1)

Mark
Mark

Reputation: 181060

I would switch to gulp-replace. gulp-regex-replace was last published 8 years ago and probably doesn't work well with gulp4.+.

I tested this with gulp-replace and it worked to remove newlines.

const replace = require('gulp-replace');

gulp.task("strip", function () {
  return (
    gulp
      .src("./*.html")
      .pipe(replace(/\r?\n/g, ''))       // simpler syntax too
      .pipe(gulp.dest("dist"))           // this is probably enough for you
  );
});

Upvotes: 1

Related Questions