C# - 正则表达式使用点替换任何字符。在括号 [ ] 中
C# - Regex replace any character using dot . in bracket [ ]
示例:
string str = "Example[1]";
string output = Regex.Replace(str, "[.]", "");
但是不行,输出还是:例[1]
虽然结果只有 "Example"?
请帮忙:(
使用以下表达式:
string output = Regex.Replace(str, @"\[\d+\]", "");
它查找符号 [
、任意数字和符号 ]
您的方法是正确的..只需在括号中使用转义字符..
string output = Regex.Replace(str, @"\[.\]", "");
输出:例子
编辑:如果括号中有多个字符.. 使用"\[.+?\]"
示例:
string str = "Example[1]";
string output = Regex.Replace(str, "[.]", "");
但是不行,输出还是:例[1]
虽然结果只有 "Example"?
请帮忙:(
使用以下表达式:
string output = Regex.Replace(str, @"\[\d+\]", "");
它查找符号 [
、任意数字和符号 ]
您的方法是正确的..只需在括号中使用转义字符..
string output = Regex.Replace(str, @"\[.\]", "");
输出:例子
编辑:如果括号中有多个字符.. 使用"\[.+?\]"