javascript - How to use basic regular expressions within gulp.src? - Stack Overflow

I'm trying to select two files with gulp.src: highcharts.js and highcharts.src.js.Of course I know

I'm trying to select two files with gulp.src: highcharts.js and highcharts.src.js.

Of course I know I could add explicitly these two with an array expression, but for learning purposes I'm trying to write a single expression for them.

I've read that one can use simple regular expression syntax but it's not clear how.

I tried

gulp.src("highcharts(\.src)?\.js")

but it didn't match any files.

I'm trying to select two files with gulp.src: highcharts.js and highcharts.src.js.

Of course I know I could add explicitly these two with an array expression, but for learning purposes I'm trying to write a single expression for them.

I've read that one can use simple regular expression syntax but it's not clear how.

I tried

gulp.src("highcharts(\.src)?\.js")

but it didn't match any files.

Share Improve this question asked Mar 30, 2016 at 9:46 Zoltán TamásiZoltán Tamási 12.8k8 gold badges70 silver badges98 bronze badges 3
  • 2 Try gulp.src("highcharts.{src.js,js}") – Wiktor Stribiżew Commented Mar 30, 2016 at 9:52
  • 1 @WiktorStribiżew thank you that actually works, even the simplified (but uglier) gulp.src("highcharts{.src,}.js") but I still wonder then how we can use actual regular expression syntax. Or maybe we can't, and I misunderstood something? – Zoltán Tamási Commented Mar 30, 2016 at 10:00
  • 1 gulp.src only support glob, or write custom function with glob + regex and pass list of files to gulp.src – YOU Commented Mar 30, 2016 at 10:13
Add a ment  | 

1 Answer 1

Reset to default 12

Gulp uses glob which doesn't support the regular expressions you're normally used to. It uses special globbing patterns that are optimized to matching files.

Your example could be written as:

gulp.src('highcharts?(.src).js')

Check out the glob primer for more examples of what's possible with glob.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743717262a4495205.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信