目標:
確保DATA1和一路data31是正確的,DATA4和一路DATA7是錯誤使用C#支持正則表達式Complemetory在自定義的正則表達式代碼
Regex regexp = new Regex(@"^[a-zA-Z]:\\.*$");
的。
問題:
data6和data7應該是錯誤的,但它是正確的。
不知道如何解決它。
Regex regexp = new Regex(@"^[a-zA-Z]:\\.*$");
//Correct result
string data1 = "C:\\33\\dd\\Desktop\\151222055438.txt";
string data2 = "c:\\ff\\ded\\Desktop\\151222055438.txt";
string data3 = "Z:\\ss\\gg\\Desktop\\151222055438.txt";
string data31 = "d:\\da\\ds\\Df\\ff.txt";
//Error result
string data4 = "3:\\rr\\555\\Desktop\\151222055438.txt";
string data5 = "d\\33\\4\\Desktop\\151222055438.txt";
string data6 = "s:\\\\rr\\d\\Desktop\\151222055438.txt";
string data7 = "s:\\\\\\f\\f\\Desktop\\151222055438.txt";
if (regexp.Match(data1).Success)
{
int correct = 23;
}
if (regexp.Match(data2).Success)
{
int correct = 23;
}
if (regexp.Match(data3).Success)
{
int correct = 23;
}
if (regexp.Match(data31).Success)
{
int correct = 23;
}
if (regexp.Match(data4).Success)
{
int error = 23;
}
if (regexp.Match(data5).Success)
{
int error = 23;
}
if (regexp.Match(data6).Success)
{
int error = 23;
}
if (regexp.Match(data7).Success)
{
int error = 23;
}
int sds = 23;
它看起來像你驗證文件名,爲什麼不使用https://stackoverflow.com/questions/422090/in-c-sharp-check-that-filename-is-possibly-valid-not-that-it-是否存在? –