tohshige / test

test private
0 stars 0 forks source link

Regex 正規表現、文字列置換 #12

Open tohshige opened 6 years ago

tohshige commented 6 years ago

正規表現で文字列置換

var replace = require('gulp-replace'); //モジュールを読み込んでおく

gulp.task('replace', function(){
  return gulp.src(['dist/dl-item20*.utf8.csv','!dist/all.csv']) //CSVを一気に読む
    .pipe(plumber({errorHandler: notify.onError('<%= error.message %>')}))
    // ダブルクオーテーション + 複数改行 を削除 
    .pipe(replace(/([^\"|\n])(\n)+/g, '$1')) 
    // ダブルクオーテーション + 単数改行 を削除 
    .pipe(replace(/(\"\n)/g, '')) 

gulpfile.js 10万箇所程度あっても2秒程度で置換が完了する