admin管理员组文章数量:1023195
I am in webpack.config
where I need to include extension to match specific file type, but I need to exclude a specific file. I googled it but didn't find a perfect solution.
What I have : /\.(?:css|less)$/
-> matches all files that have .less OR .css
but here I want to add "not only -> test.something_strict.less" /\.(?:css|less|!test.less)$/
where test.something_strict is a file name with extension .less
and only exclude test.something_strict
but this didn't work, this matches .less or .css
and pass through the test.
I am in webpack.config
where I need to include extension to match specific file type, but I need to exclude a specific file. I googled it but didn't find a perfect solution.
What I have : /\.(?:css|less)$/
-> matches all files that have .less OR .css
but here I want to add "not only -> test.something_strict.less" /\.(?:css|less|!test.less)$/
where test.something_strict is a file name with extension .less
and only exclude test.something_strict
but this didn't work, this matches .less or .css
and pass through the test.
- 1 I don't fully understand your specifications. But based on your info is this okay? – Rahul Commented May 22, 2017 at 19:50
- @Rahul, you get me right. – Ash Commented May 22, 2017 at 19:54
- Too late to post answer though. ☺☻ – Rahul Commented May 22, 2017 at 19:55
- @Rahul, you can post it, as an alternative. – Ash Commented May 22, 2017 at 19:55
- 1 @AshishMishra: Your new specification is totally different from previous one. – Rahul Commented May 22, 2017 at 20:00
1 Answer
Reset to default 7|!test.less
doesn't really negate matching test.less
. It will literally match !
before test.less
.
You can use this regex:
/^(?!test\.[^.]+\.less$).+\.(?:css|less)$/m
RegEx Demo
(?!test\.less$)
is a negative lookahead that will assert failure if filename is test.<anything>.less
.
I am in webpack.config
where I need to include extension to match specific file type, but I need to exclude a specific file. I googled it but didn't find a perfect solution.
What I have : /\.(?:css|less)$/
-> matches all files that have .less OR .css
but here I want to add "not only -> test.something_strict.less" /\.(?:css|less|!test.less)$/
where test.something_strict is a file name with extension .less
and only exclude test.something_strict
but this didn't work, this matches .less or .css
and pass through the test.
I am in webpack.config
where I need to include extension to match specific file type, but I need to exclude a specific file. I googled it but didn't find a perfect solution.
What I have : /\.(?:css|less)$/
-> matches all files that have .less OR .css
but here I want to add "not only -> test.something_strict.less" /\.(?:css|less|!test.less)$/
where test.something_strict is a file name with extension .less
and only exclude test.something_strict
but this didn't work, this matches .less or .css
and pass through the test.
- 1 I don't fully understand your specifications. But based on your info is this okay? – Rahul Commented May 22, 2017 at 19:50
- @Rahul, you get me right. – Ash Commented May 22, 2017 at 19:54
- Too late to post answer though. ☺☻ – Rahul Commented May 22, 2017 at 19:55
- @Rahul, you can post it, as an alternative. – Ash Commented May 22, 2017 at 19:55
- 1 @AshishMishra: Your new specification is totally different from previous one. – Rahul Commented May 22, 2017 at 20:00
1 Answer
Reset to default 7|!test.less
doesn't really negate matching test.less
. It will literally match !
before test.less
.
You can use this regex:
/^(?!test\.[^.]+\.less$).+\.(?:css|less)$/m
RegEx Demo
(?!test\.less$)
is a negative lookahead that will assert failure if filename is test.<anything>.less
.
本文标签: javascriptregex match extension but exclude a specific fileStack Overflow
版权声明:本文标题:javascript - regex match extension but exclude a specific file - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745553763a2155751.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论