JavaScript RegEx 排除特定文件扩展名和 index.js

JavaScript RegExp exclude specific file extension and index.js

这是我当前的正则表达式:

/^(?!index).*js/gmi

这是应用 RegExp 的列表:

test/test.js
hey/test-bundle.js
test/test-heybundle.js
test/index.js
test/indop.js
lollipop/testindex.js
test/test.scss
test/test.css
lalilu/hey.yml
test.js

它应该做什么:

我非常感谢任何帮助让这个 RegExp 像预期的那样工作。

/^[a-z]+\/(?!index\.js$)[a-z]+(?!-bundle)(?:-[a-z]+)?\.js$/gm

https://regex101.com/r/Yqaajy/1

^[a-z]+\/ - 匹配父目录(假设目录分隔符始终是 /)。

(?!index\.js$) - 如果父目录后跟 index.js 和行尾,则匹配失败。

[a-z]+(?!-bundle) - 一个或多个字母后面没有跟 -bundle

(?:-[a-z]+)? - 连字符后的文件名的可选第二部分。如果您还有包含超过 2 个带连字符的部分的文件,请将 ? 更改为 *

\.js$ - 文件扩展名和行尾。