我正在尝试删除[/quote]
我目前有这个:
Comment = Regex.Replace(Comment, @"[/quote](\n){1,}", "[/quote]");
但它似乎没有做任何事情!
示例:
[/quote]
hey nice quote blah blah
转到
[/quote]hey nice quote blah blah
答案 0 :(得分:3)
你确定你的字符串以\n
结尾(UNIX风格的行结尾),而不是\r\n
(Windows风格的行结尾)?
另外,请注意正则表达式中的[...]
表示字符类,因此[/quote]
匹配单个字符/
,q
,{{1} },u
,o
或t
。您必须将e
转义为[
以匹配开括号字符。
将它们放在一起(并将\[
简化为速记{1,}
),然后尝试:
+
答案 1 :(得分:0)
在“\ n”之后添加“+”以匹配所有\ n的
答案 2 :(得分:0)
你还需要逃脱换行符 [/报价] [\\ N] +
答案 3 :(得分:0)
尝试使用此正则表达式
string strRegex = @"\[/quote\][\n\r]+";
Regex myRegex = new Regex(strRegex);
string strReplace = "[/quote]";
return myRegex.Replace(strTargetString, strReplace);