日期:2014-05-18 浏览次数:20969 次
第一段 第二段 第三段 第四段 dev-super 82 node23 public_index_site12_org12_n12_i3_p3.html dev-super 82 news/node23 public_index_site12_org12_group13_n12_i3_view12_p3.html … dev-super 82 index_p3.html …
Uri uri = new Uri("http://dev-super:82/news/node23/node21/index.html");
string[] segments = uri.Segments;
Console.WriteLine("{0} {1} {2} {3}", uri.Host, uri.Port, string.Join(string.Empty, segments, 0, segments.Length - 1), segments[segments.Length - 1]);
------解决方案--------------------
“/”个数>=4时,用:http://(.+?):(\d+)/(.*)/([^/]+)$
“/”个数<=3时,用:http://(.+?):(\d+)/([^/]+)$
------解决方案--------------------
string str = @"http://dev-super:82/node23/public_index_site12_org12_n12_i3_p3.html
http://dev-super:82/news/node23/public_index_site12_org12_group13_n12_i3_view12_p3.html
http://dev-super:82/node23/news/public_index_site12_org12_n12_i3_p3.html
http://dev-super:82/news/node23/node21/index.html
http://dev-super:82/node23/news/index.html
http://dev-super:82/node23/index.html
http://dev-super:82/index_p3.html
http://dev-super:82/public_index123_site12_org12_group13_n12_i3_view12_p3.html";
Regex reg = new Regex(@"(?is)http://([^:]+):([^/]+)/([^.]*/)?(.*?html)");
foreach (Match m in reg.Matches(str))
Console.WriteLine("{0} {1} {2} {3}\r\n", m.Groups[1].Value, m.Groups[2].Value, m.Groups[3].Value.Length==0?"空":m.Groups[3].Value, m.Groups[4].Value);
/*
dev-super 82 node23/ public_index_site12_org12_n12_i3_p3.html
dev-super 82 news/node23/ public_index_site12_org12_group13_n12_i3_view12_p3.htm
l
dev-super 82 node23/news/ public_index_site12_org12_n12_i3_p3.html
dev-super 82 news/node23/no