I am very new to RegEx -- so can someone please help me figure out what exactly is going wrong here?
I have this code:
string regPattern = "*[~#%&*{}/<>?|\"-]+*";
string replacement = "";
Regex regExPattern = new Regex(regPattern);
Yet, when my app hits the regExPattern line, i get an ArgumentException -- Quantifier {x,y} following nothing error.
Can someone help?
EDIT: I need to pass this pattern into a foreach loop like so:
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
}
How do i define the pattern if it is being passed into this loop?