私は正規表現に非常に慣れていないので、誰かがここで何が間違っているのかを正確に理解するのを手伝ってくれませんか?
私はこのコードを持っています:
string regPattern = "*[~#%&*{}/<>?|\"-]+*";
string replacement = "";
Regex regExPattern = new Regex(regPattern);
それでも、アプリがregExPattern行に到達すると、何もエラーが発生しなかった後、ArgumentException --Quantifier{x、y}が発生します。
誰かが助けることができますか?
編集:このパターンを次のようにforeachループに渡す必要があります:
if (paths.Contains(regPattern))
{
foreach (string files2 in paths)
{
try
{
string filenameOnly = Path.GetFileName(files2);
string pathOnly = Path.GetDirectoryName(files2);
string sanitizedFileName = regExPattern.Replace(filenameOnly, replacement);
string sanitized = Path.Combine(pathOnly, sanitizedFileName);
//write to streamwriter
System.IO.File.Move(files2, sanitized);
}
catch (Exception ex)
{
//write to streamwriter
}
}
}
else
{
//write to streamwriter
}
このループに渡される場合、パターンを定義するにはどうすればよいですか?