简体   繁体   中英

Regex Exclude folder from path

I have a bunch of files like these

/foo/bar/specs/d.js
/foo/bar/spec/d.js
/foo/bar/specs/v.js
/foo/bar/specs/v.js
/node_modules/bar/specs/v.js

I need a regex that will exclude everything under node_modules

Something like this:

(?!node_modules)\/.*\/specs\/.*\.js

Unfortunately it isnt working

Appreciate your help.

Probably something like this?

 let arr = [ '/foo/bar/specs/d.js', '/foo/bar/specs/d.js', '/foo/bar/specs/v.js', '/foo/bar/specs/v.js', '/node_modules/bar/specs/v.js' ] arr.forEach(s => console.log(/^\\/(?!node_modules).*\\/.*\\/specs\\/.*\\.js/.test(s))) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM