最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin4PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far