Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex match extension but exclude a specific file

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.

like image 833
Ash Avatar asked Nov 26 '25 03:11

Ash


1 Answers

|!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.

like image 50
anubhava Avatar answered Nov 28 '25 15:11

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!