当前位置:编程学习 > C#/ASP.NET >>

我要通过C#取所有超连接

我想通过C#提取所有文本框内所有的超连接怎么取的呢
请高手们帮我一个忙
通过C#程序实现,比如里面有全部文本信息,
如以下内容:
http://zhidao.baidu.com/question/102440411.html里面的还其它信息,包手<A等...
http://zhidao.baidu.com/question/105773275.html
<a  href="/question/102440411.html">新闻</a>
<a  href="/question/102440412.html">新闻</a>
<a  href="/question/102440413.html">新闻</a>
<a  href="/question/102440414.html">新闻</a>
....等..
textBox.text里面所有的网页超连接取出来放到ListBox1.text里面

用什么方法把textBox.text的所以超连接取出来的呀  --------------------编程问答-------------------- 用正则 --------------------编程问答-------------------- jquery  :$(":a")  可以取所有的。 
/^(src|href)=[\'\"]http:\/\/(.*)/is 
你也可以采用使用正则表达式的方法取~ 
例如http://sports.sina.com.cn/global/ 需要把里面所有的连接的url拿出来并输出成列表大概就所有 a href = "http://xxxx.xxxx.xx" 中的http://xxxx.xxxx.xx拿出来然后输出成列表例如google.com的输出大概就会是 images.google.com/imghp?hl=en&tab=wi maps.google.com/maps?hl=en&tab=wl news.google.com/nwshp?hl=en&tab=wn www.google.com/prdhp?hl=en&tab=wf mail.google.com/mail/?hl=en&tab=wm www.google.com/intl/en/options/ video.google.com/?hl=en&tab=wv groups.google.com/grphp?hl=en&tab=wg books.google.com/bkshp?hl=en&tab=wp scholar.google.com/schhp?hl=en&tab=ws finance.google.com/finance?hl=en&tab=we blogsearch.google.com/?hl=en&tab=wb www.youtube.com/?hl=en&tab=w1 www.google.com/calendar/render?hl=en&tab=wc picasaweb.google.com/home?hl=en&tab=wq docs.google.com/?hl=en&tab=wo www.google.com/reader/view/?hl=en&tab=wy sites.google.com/?hl=en&tab=w3 www.google.com/intl/en/options/ 
如果可以的话多给点分吧!!!!!!!!!!!!!!!!!!!!!!! --------------------编程问答-------------------- try...
Regex re = new Regex(@"http://(?<url>[^\u4e00-\u9fa5\s]*)|<a\s*href=""(?<url>[^""]*)""[^>]*>");
            string s = @"http://zhidao.baidu.com/question/102440411.html里面的还其它信息,包手 <A等... 
http://zhidao.baidu.com/question/105773275.html 
<a  href=""/question/102440411.html"">新闻 </a> 
<a  href=""/question/102440412.html"">新闻 </a> 
<a  href=""/question/102440413.html"">新闻 </a> 
<a  href=""/question/102440414.html"">新闻 </a> ";
            Match m;
            for (m = re.Match(s); m.Success; m = m.NextMatch())
            {
                Console.WriteLine(m.Groups["url"].ToString());
            }
--------------------编程问答-------------------- 优化了下
 static void Main(string[] args)
        {
            Regex re = new Regex(@"(?<url>\bhttp://[^\u4e00-\u9fa5\s]*)|<a\s*href=""(?<url>[^""]*)""[^>]*>");
            string s = @"http://zhidao.baidu.com/question/102440411.html里面的还其它信息,包手 <A等... 
http://zhidao.baidu.com/question/105773275.html 
<a  href=""/question/102440411.html"">新闻 </a> 
<a  href=""/question/102440412.html"">新闻 </a> 
<a  href=""/question/102440413.html"">新闻 </a> 
<a  href=""/question/102440414.html"">新闻 </a> ";
            Match m;
            for (m = re.Match(s); m.Success; m = m.NextMatch())
            {
                Console.WriteLine(m.Groups["url"].ToString());
            }
        }
--------------------编程问答-------------------- 楼上是高手。

鉴定完毕  
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,