首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

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

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

热点排行