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

正则字符串中含有超连接代码

要判断字符串中是否有url连接代码,我们正则 @"(http|ftp|https教程)://[w]+(.[w]+)([w-.,@?・^=%&:/~+#]*[w-@?^=%&/~+#])";,下面我们用一个实例来说明。

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;
        }

 

补充:asp.net教程,.Net开发 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,