日期:2014-05-18 浏览次数:20811 次
$[s1]这里是第一个<br/> 这里显示的时候是下一行.也就是\n\r $[s2]this is 2个 $[s3]this 是第三个 CDSN论坛 谢谢各位了 $[s4]这里第四个
这里是第一个<br/> this is 2个 this 是第三个 这里第四个
static void Main(string[] args)
{
string str = @"$[s1]这里是第一个<br/>
这里显示的时候是下一行.也就是\n\r
$[s2]this is 2个
$[s3]this 是第三个
CDSN论坛
谢谢各位了
$[s4]这里第四个";
Regex re = new Regex(@"(?is)\$\[[^]]+\](?<s1>[^\n]+)\s*.*?\$\[[^]]+\](?<s2>[^\n]+)\s*.*?\$\[[^]]+\](?<s3>[^\n]+)\s*.*?\$\[[^]]+\](?<s4>[^\n]+)\s*.*?", RegexOptions.None);
Match ma = re.Match(str);
Console.WriteLine(ma.Groups["s1"].Value);
Console.WriteLine(ma.Groups["s2"].Value);
Console.WriteLine(ma.Groups["s3"].Value);
Console.WriteLine(ma.Groups["s4"].Value);
Console.ReadLine();
}
------解决方案--------------------
正则不变,替换成空就行了。
string r = Regex.Replace(s, @"(?s)\$\[.+?\][^\r\n$]+", "");
Response.Write(Server.HtmlEncode(r));