Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I exclude a string if it ends in ".d.ts"?

Tags:

regex

gulp

glob

I am using regex type glob to include files in gulp. How can I use a regex to ignore strings that end with a ".d.ts" but include all others?

Already I have this:

"app/*.*" 

but it's including filenames with any ending.

Is there a way I can limit it to just those not ending in .d.ts? So for example these would be okay:

app/abc.html
app/abc.js
app/abc.ts

But this would not

app/abc.d.ts
like image 881
Samantha J T Star Avatar asked Jan 09 '23 04:01

Samantha J T Star


2 Answers

In your src definition, you can use bang (!) to exclude paths, like:

gulp.src(['path/to/src/**/*.*', '!path/to/src/**/*.d.ts'])

The minimatch documentation discusses the bang syntax.

Just noticed this related question has additional details.

like image 59
bishop Avatar answered Jan 17 '23 02:01

bishop


.*(?<!\.d\.ts)$

Regular expression visualization

Debuggex Demo

(assuming lookbehind assertions are supported by your regex flavor. I dont know "gulp")

like image 34
Damien Overeem Avatar answered Jan 17 '23 02:01

Damien Overeem