我希望清理包含文件路径的字符串,以删除父路径以获得更安全的日志记录。
需要:
我想要一个多行字符串,如:
The file was: C:\\outputpath\\testfile.htm
And the second file was: C:\\OutputPath\\subfolder\\testfile2.htm'
让它找到并替换为输出:
The file was: testfile.htm
The second file was: subfolder\\testfile2.htm
我一直在尝试这个:
var pathToRemove = "c:\\outputPath";
var sourceRegex = new Regex(".*(" + pathToRemove + ").*", RegexOptions.IgnoreCase);
var sanity = sourceRegex.Replace(input, String.Empty, 1000);
我得到了一个例外
Unrecognized escape sequence \o.
答案 0 :(得分:3)
string pathToRemove = @"c:\\outputpath\\";
Regex sourceRegex = new Regex(pathToRemove, RegexOptions.IgnoreCase);
string sanity = sourceRegex.Replace(input, string.Empty);