Reputation: 852
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.
Upvotes: 2
Views: 12057
Reputation: 3574
Here's a regex that gets .ts and .js files that are not in the .git or node_modules folder:
^(?!.*\/(node_modules|\.git)\/).*(.ts|.js)$
Explanation:
^
(?!.*\/(node_modules|\.git)\/)
(.ts|.js)
$
Upvotes: 0
Reputation: 2720
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)))
Upvotes: 6