用单个Regex.Replace()替换多个字符串Replace()

iLe*_*ing 2 regex c#-4.0

如果我这样做的话:

someString.Replace("abc","").Replace("def","").Replace(@"c:\Windows","")
Run Code Online (Sandbox Code Playgroud)

我怎样才能替换它

Regex.Replace(someString," \\here I don't know what the pattern should be")
Run Code Online (Sandbox Code Playgroud)

我试过这个:

Regex.Replace(someString, @"(?:abc|def|c:\Windows)")
Run Code Online (Sandbox Code Playgroud)

但它不起作用

UPD ...

问题是当我通过这样的路径时

Regex.Replace(someString, @"(?:abc|def|"+aPath+")")
Run Code Online (Sandbox Code Playgroud)

Cod*_*key 6

`But it didnt work` doesn't say much helpfull!
Run Code Online (Sandbox Code Playgroud)

试试这个:

someString = Regex.Replace(someString, @"(?:abc|def|ghi|c:\\Windows)", "")
Run Code Online (Sandbox Code Playgroud)

我尝试的时候确实有效.我认为你的代码不起作用的原因是你忘记了替换字符串,你必须逃避路径中的反斜杠.