Since ignore
can take a regex, pass ignore
a Ruby regex //
instead of a string ""
with a filename glob. In the regex, use negative lookahead (?!)
and the end-of-string anchor $
to check that the filename doesn’t end in “.css”.
ignore /^ css\/inuit\.css\/ (?: [^.]+ | .+ \. (?!css) \w+ ) $/ix
This regex correctly handles all of these test cases:
- Should match:
css/inuit.css/abc.html
css/inuit.css/thecssthing.json
css/inuit.css/sub/in_a_folder.html
css/inuit.css/sub/crazily.named.css.json
css/inuit.css/sub/crazily.css.named.json
css/inuit.css/LICENSE
- Shouldn’t match:
css/inuit.css/realcss.css
css/inuit.css/main.css
css/inuit.css/sub/in_a_folder.css
css/inuit.css/sub/crazily.css.named.css
css/inuit.css/sub/crazily.named.css.css
The first alternation of the (?:)
non-capturing group handles the case of files with no extension (no “.”). Otherwise, the second case checks that the last “.” in the path is not followed by “css”, which would indicate a “.css” extension.
I use the x
flag to ignore whitespace in the regex, so that I can add spaces in the regex to make it clearer.