저는 RegEx를 처음 사용하기 때문에 누군가 정확하게 여기에 잘못되어있는 것이 무엇인지 알아낼 수 있습니까? 아무것도 오류 다음 한정 기호 {X, Y} - 내 앱이 regExPattern 라인을 칠 때RegEx - 아무런 오류가없는 한정자 {x, y}
string regPattern = "*[~#%&*{}/<>?|\"-]+*";
string replacement = "";
Regex regExPattern = new Regex(regPattern);
아직, 내가 ArgumentException이 얻을 :
나는이 코드를 가지고있다.
누군가 도움을 줄 수 있습니까?
편집 : 나는 그렇게처럼 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
}
어떻게 패턴을 정의합니까이이 루프로 전달되는 경우?
구체적으로 말해서 코드에있는 패턴은 파일 이름에 유효하지 않은 문자를 없애기위한 것입니다. 따라서 별표, 물결표, 파운드 기호, 대괄호, 꺾쇠 괄호 등을 제거해야합니다. 이것이 올바른 패턴입니까? – yeahumok