开发者

Regex in C# that contains "this" but not "that

I need to filter a list of files. Some of these are csv files, and of those, some of them are appended with a control tag, ".cntl".

Example: file1.csv, file1.csv.cntl

I would like to set up a regex that checks to see if a file contains "csv" and NOT "cntl". Right now I've got this.开发者_Go百科

csv(?!cntl)

This is not working. What would a proper regex be?

PS. This is all done in C#.


Your regex should check to see if a file ends with .csv

\.csv$

Remember that csv could be contained elsewhere in the file name.


The following is the pattern you want.

@"csv(?!\.cntl)"

But, wouldn't it be easier to check:

if (string.EndsWith("cntl"))

Using a regex is unnecessarily complicated.


This should work:

csv(?!.*cntl)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜