日期:2014-05-17 浏览次数:20906 次
string test = @"
1f2dsa1f3dsa
456
fdsaf1ds2af1dsa1fds2a3f123sda1fdsa
";
Regex regN = new Regex(@"[^\n]+");
Regex regR = new Regex(@"[^\r]+");
MatchCollection mc = regN.Matches(test);
richTextBox2.Text += "[^\\n]+匹配结果:\n";
foreach (Match m in mc)
{
richTextBox2.Text += "-Start-" + m.Value + "-End-\n";
}
richTextBox2.Text += "==========华丽的分割线==========\n";
richTextBox2.Text += "[^\\r]+匹配结果:\n";
mc = regR.Matches(test);
foreach (Match m in mc)
{
richTextBox2.Text += "-Start-" + m.Value + "-End-\n";
}
/*-----输出-----
[^\n]+匹配结果:
-Start-
-End-
-Start-
-End-
-Start-1f2dsa1f3dsa
-End-
-Start-
-End-
-Start-456
-End-
-Start-
-End-
-Start-fdsaf1ds2af1dsa1fds2a3f123sda1fdsa
-End-
==========华丽的分割线==========
[^\r]+匹配结果:
-Start-
-End-
-Start-
1f2dsa1f3dsa-End-
-Start-
-End-
-Start-
456-End-
-Start-
-End-
-Start-
fdsaf1ds2af1dsa1fds2a3f123sda1fdsa-End-
-Start-
-End-
*/