[英]Regular Expression for multiple folder names in URL and Excluded Extension Flags
I'm processing multiple js files to build bundles via webpack.我正在处理多个 js 文件以通过 webpack 构建捆绑包。 However I need to target multiple js files to process across multiple folders, while being able to exclude js files with certain flags in the filename.
但是,我需要定位多个 js 文件以跨多个文件夹进行处理,同时能够排除文件名中带有某些标志的 js 文件。
I have the following files:我有以下文件:
/styles/portal/version2/libraries/jquery.js
/styles/portal/version2/libraries/library.exclude.js
/styles/portal/version2/components/componenta.js
/styles/portal/version2/konstructs/konstructa.js
/styles/portal/version2/konstructs/konstructb.js
/styles/portal/version2/konstructs/konstructc.js
/styles/portal/version2/konstructs/konstructd.disabled.js
/styles/portal/version2/vendors/vendor.js
/styles/portal/version2/vendors/vendor.exclude.js
And this should only grab the following files to bundle:这应该只抓取以下文件进行捆绑:
/styles/portal/version2/libraries/jquery.js
/styles/portal/version2/konstructs/konstructa.js
/styles/portal/version2/konstructs/konstructb.js
/styles/portal/version2/konstructs/konstructc.js
/styles/portal/version2/vendors/vendor.js
So essentially any.js file out of the specific libraries , konstructs , vendor folders and then don't include anything with disabled.js or exclude.js所以基本上 any.js 文件来自特定的library , konstructs , vendor文件夹,然后不包含disabled.js或exclude.js的任何内容
To get the three directories libraries, konstructs or vendors
that contain获取三个目录
libraries, konstructs or vendors
包含
non- disabled
nor exclude
in the file name parts of .js
files would be this: .js
文件的文件名部分中的非disabled
或exclude
将是:
/^.*?\/(?:libraries|konstructs|vendors)(?=\/)(?:[^\/.]*\/)*(??[^\/]*?\b(:?disabled|exclude)(.=\?)[^\/]*.\?js$)[^\/]*.\.js$/gm
https://regex101.com/r/rTUfeQ/1 https://regex101.com/r/rTUfeQ/1
Note, use the multi-line modifier if looking at multi-line strings.注意,如果查看多行字符串,请使用多行修饰符。
If not, no need for it.如果没有,则不需要它。
You can try exclude option in rule-condition with this pattern您可以尝试使用此模式在规则条件中排除选项
/\.(exclude|disabled)\.js$/
\.
- Matches .
.
(exclude|disabled)
- Match exclude
or disabled
word (exclude|disabled)
- 匹配exclude
或disabled
词\.js
- Matches . followed by js
\.js
- 匹配. followed by js
. followed by js
$
- End of string $
- 字符串结束
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.