0
Follow
2
View

regex for files of a particular file extension that exclude one particular word [duplicate]

leila0329 注册会员
2023-01-26 03:44

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 re 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

flashgirl_xm 注册会员
2023-01-26 03:44

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'))

About the Author

Question Info

Publish Time
2023-01-26 03:44
Update Time
2023-01-26 03:44