获取字符串中含有超连接内容

        private List<string> getURLFromContent(string content)
        {
            string regexStr = @"(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?・^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])";           

            System.Text.RegularExpressions.MatchCollection mc = System.Text.RegularExpressions.Regex.Matches(content, regexStr,               System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            List<string> urlStr = new List<string>();
            for (int i = 0; i < mc.Count; i++)
            {
                if(!urlStr.Contains(mc[i].ToString()))
                {
                    urlStr.Add(mc[i].ToString());
                }
            }
            return urlStr;
        }

posted @ 2011-02-12 18:20  spring yang  阅读(414)  评论(0编辑  收藏  举报