简体   繁体   English

正则表达式从路径中排除文件夹

[英]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 我需要一个正则表达式,它将排除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))) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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