读书人

Asp.net怎么判断文本框中含有网站链接

发布时间: 2012-08-25 10:06:20 作者: rapoo

Asp.net如何判断文本框中含有网站链接
一个文本框,如何判断这个文本框中有一个或者多个网站链接如http://a.com。

[解决办法]
是禁用链接还是要做什么操作,

JS+正则 判读http:// 和.com、.cn
[解决办法]

探讨
引用:

是禁用链接还是要做什么操作,

JS+正则 判读http:// 和.com、.cn
就是一个文本框,我要把里面的URL全部提取出来,放到一个数组当中。

[解决办法]
C# code
public String ReplaceLink(String pubh_desc)    {        System.Text.RegularExpressions.MatchCollection matchs = Regex.Matches(pubh_desc, "<a[^>]*href=(['\"]?)(?<url>(?:\\\\\"|[^\"'\\s>])*)\\1[^>]*>(?<text>[\\s\\S]*?)</a>", RegexOptions.IgnoreCase);        for (int i = 0; i < matchs.Count; i++)        {            string str = matchs[i].Groups["url"].ToString();            if (!string.IsNullOrEmpty(str) && !str.Equals("#"))            {                String[] urls = str.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);                String SpitUrl = String.Empty;                if (urls != null && urls.Length > 1)                {                    SpitUrl = urls[1];                }                pubh_desc = pubh_desc.Replace(matchs[i].Value, string.Format("<a href=\"javascript:void(0)\">{0}</a>", matchs[i].Groups["text"]));            }        }        return pubh_desc;    } 

读书人网 >asp.net

热点推荐