我需要簡單地看看是否有任何匹配的文件名中的一組特殊字符我已經嘗試過所有常見的正則表達式,包括下面的那些。所有這些例子都會找到除括號外的任何特殊字符。C#在文件名中找到特殊字符
Regex.Match(filename, "[\\[\\]{}[email protected]#]");
// I even separated this out into 3 like this
Regex.Match(filename, "[");
Regex.Match(filename, "]");
Regex.Match(filename, "[{}[email protected]#]");
filename.IndexOfAny("[]{}[email protected]#".ToCharArray()) != -1
什麼給了?
當你說特殊字符時,你是什麼意思?是什麼讓他們對你的用例「特殊」? – Oded
方括號專門打破我們的系統,所以我們不能允許上載括號的文件。 –
「括號」,你的意思是方形的[和]? ({}被一些人稱爲花括號。) –