string text = "I'vefoundthisamazingURLathttp://www.sohu.com,andthenfindftp://ftp.sohu.comisbetter.";
string pattern = @"b(?<protocol>S+)://(?<address>S+)b";
MatchCollection mc = Regex.Matches(text,pattern);
Response.Write("文本中包含的URL地址有:");
foreach(Match match in mc)
{
GroupCollection gc = match.Groups;
string outputText = "URL:" + match.Value + ";Protocol:" + gc["protocol"].Value + ";Address:" + gc["address"].Value;
Response.Write(outputText);
}输出为空,我想输出
http://www.sohu.com
ftp://ftp.sohu.com 哪里不对了呢???
string pattern = @"b(?<protocol>S+)://(?<address>S+)b";
MatchCollection mc = Regex.Matches(text,pattern);
Response.Write("文本中包含的URL地址有:");
foreach(Match match in mc)
{
GroupCollection gc = match.Groups;
string outputText = "URL:" + match.Value + ";Protocol:" + gc["protocol"].Value + ";Address:" + gc["address"].Value;
Response.Write(outputText);
}输出为空,我想输出
http://www.sohu.com
ftp://ftp.sohu.com 哪里不对了呢???
解决方案 »
- 求快速地更新大批量数据方案
- 请问如何将一个表中的数据循环插入5000次啊?
- vs2005中的asp.net development server在属性窗口找不到虚拟路径
- 使用ajax后gridview导出excel中文是乱码阿,怎么办?
- IIS 6.0 如何让404 错误转向到一个ASPX页面上
- 200分求一个正则表达式,关于多匹配html元素的,求高人相助
- 外部有个string ls的变量,内部又有一个相同的ls的变量,请问能否在内部调用外部ls变量?
- 将数据库连接缓存在 Application 中是不是很占服务器资源??
- Infragistics的UltraWebTab中怎样嵌入DataGrid或者UltraWebGrid控件
- asp.net获取javascript中的值是否有方法
- 在线请教:jquery调用几种WebService类型的性能区别,谢谢
- mvc怎样做个查询
string text = "I'vefoundthisamazingURLathttp://www.sohu.com,andthenfindftp://ftp.sohu.comisbetter.";
System.Text.RegularExpressions.Regex reg= new System.Text.RegularExpressions.Regex(@"(http|ftp)://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?", RegexOptions.IgnoreCase);
MatchCollection mc = reg.Matches(text); ;
Console.WriteLine("文本中包含的URL地址有:");
foreach (Match match in mc)
{
string url = match.Value;
string outputText = "URL:" + url.Substring(url.IndexOf("//")+2) +";Protocol:" + url.Substring(0, url.IndexOf(":"));
Console.WriteLine(outputText);
}
Console.ReadLine();
if(!Regex.Match(text,@"b(?<protocol>S+)://(?<address>S+)b").Success)
{
...
}
)