C#中包含“this"的正则表达式但不是“那个 [英] Regex in C# that contains "this" but not "that

查看:51
本文介绍了C#中包含“this"的正则表达式但不是“那个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要过滤文件列表.其中一些是 csv 文件,其中一些附加了控制标签.cntl".

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

示例:file1.csv、file1.csv.cntl

Example: file1.csv, file1.csv.cntl

我想设置一个正则表达式来检查文件是否包含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.

csv(?!cntl)

这不起作用.什么是正确的正则表达式?

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

附注.这一切都是在 C# 中完成的.

PS. This is all done in C#.

推荐答案

您的正则表达式应该检查文件是否以 .csv

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

\.csv$

请记住,csv 可以包含在文件名的其他位置.

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

这篇关于C#中包含“this"的正则表达式但不是“那个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆