lazd / gulp-replace

A string replace plugin for gulp
MIT License
496 stars 88 forks source link

Using regex can only replace the first match in every file. #93

Closed ycj1905 closed 7 years ago

ycj1905 commented 7 years ago

The regex will match (/ /) and it has no problem for my IDE to replace globally .

However I write some codes below, and it will only replace the first match in every files.

Did I do something wrong ?

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

var re1 = new RegExp('/\\*(\\*)?(((?!\\*/)[\\s\\S])+)?\\*/');

gulp.task('regex', function(){
  // gulp.src(['src/**/*.ts'])
  gulp.src(['src/**/*.ts'])
    .pipe(replace(re1, ' REMOVE SUCCESS ! '))
    .pipe(gulp.dest('build/'));
});

Before

2017-11-07 12 17 56

After

2017-11-07 12 17 33
ycj1905 commented 7 years ago

well that's my fault ...

change to global will work fine :

var re1 = new RegExp('/\\*(\\*)?(((?!\\*/)[\\s\\S])+)?\\*/', 'g');