I want to exclude file paths that have capsize anywhere in the path in node or javascript but I am failing to get the syntax right.
const re = /.*((?!capsize).*)\.css\.ts/;
console.log(re.test('src/packages/graph.css.ts')) // should be true
console.log(re.test('packages/vanilla-extract/capsize.css.ts')) // should be false
First you need to specify, that you want to match whole string, ie. add start and end mark. (Otherwise it will skip .* as no symbol were matched, which is ok from regex point of view)
Second you need to put not follow by right after any symbol (ie. saying, there can be 0 to infinity symbols not followed by capsize).
const re = /^(.(?!capsize))*\.css\.ts$/;
console.log(re.test('src/packages/graph.css.ts')) // should be true
console.log(re.test('packages/vanilla-extract/capsize.css.ts')) // should be false
One possible way:
const re = /^(?!.*?capsize).*\.css\.ts$/;
console.log(re.test('src/packages/graph.css.ts')) // should be true
console.log(re.test('packages/vanilla-extract/capsize.css.ts'))