请以正则表达式,实现功能如下:
现有Url 如下:
A. http://www.repair.com/haocer/
B. http://www.repair.com/haocer/index.aspx
C. http://www.repair.com/index.aspx要用正则表达式提取url中"/?/"中的内容,相当于 A 中的“haocer”,而且在B或者C 得情况提取“haocer”或者不与提取
现有Url 如下:
A. http://www.repair.com/haocer/
B. http://www.repair.com/haocer/index.aspx
C. http://www.repair.com/index.aspx要用正则表达式提取url中"/?/"中的内容,相当于 A 中的“haocer”,而且在B或者C 得情况提取“haocer”或者不与提取
Regex reg = new Regex(@"(?<!//)(?<=/)[^/]+(?=/)");
foreach (string s in test)
{
richTextBox2.Text += "源字符串: " + s + " 匹配结果: " + reg.Match(s).Value + "\n";
}