识别URL超链接

自动识别 URLRegex urlregex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)",
自动识别 URL   RegexOptions.IgnoreCase
|RegexOptions.Compiled);

识别Email
自动识别 URLRegex emailregex = new Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)",
自动识别 URL   RegexOptions.IgnoreCase
|RegexOptions.Compiled);

当程序已经识别出URL超链接或Email地址后,必须用<a href=...>超链接</a>对这些超链接进行替换,这样才能把这些文字显示为链接的形式。我这里把它们全部包含在函数中:

自动识别 URLprivate void Button1_Click(object sender, System.EventArgs e)
}


去除HTML标记

自动识别 URLContentStr     =   System.Text.RegularExpressions.Regex.Replace(ContentStr,"<[^>]*>",   "");   

内容中提取指定标记

自动识别 URLstring content = "这里是新闻内容<IMG src=\"/images/index.jpg\" style=\"width:280px;height:160px;\">sdfsdfsdfsdf<img src='ddd'>";
自动识别 URL
自动识别 URLRegex reg 
= new Regex(@"<img[^>]*>",RegexOptions.IgnoreCase|RegexOptions.Compiled|RegexOptions.RightToLeft);
自动识别 URL        
foreach (Match m in reg.Matches(content))
        }

相关文章:

  • 2022-12-23
  • 2021-12-28
  • 2021-09-19
  • 2021-09-10
  • 2021-05-18
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2021-06-21
相关资源
相似解决方案