如果我有几个字符串:
str = "This is a cool string (orch. details here): 2. Denied." str2 = " (Orch. details here)" <--notice the capital letter
然后我做这行代码试图清除那部分:
str3 = Regex.Replace(str, str2, "", RegexOptions.IgnoreCase);
str3
最终完全像str
执行前一样.我怀疑它是不是"看到"其他人物,如周期,因为当我做这与只是简单的字母str
和str2
那么它将取代它就好了.
是什么赋予了?!:)
感谢您的任何见解!
parens和period都有正则表达式的含义.因此,它不是试图字面上匹配的内容,str2
而是一个由定义的正则表达式str2
.如果你想要它按字面意思匹配你需要转义字符串
str2 = Regex.Escape(str2);