Asp.net如何判断文本框中含有网站链接
一个文本框,如何判断这个文本框中有一个或者多个网站链接如http://a.com。
[解决办法]
是禁用链接还是要做什么操作,
JS+正则 判读http:// 和.com、.cn
[解决办法]
[解决办法]
- 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; }