自动识别超链接
2009-06-08 21:14
316 查看
/// <summary>
/// 自动识别超链接
/// </summary>
/// <param name="Text"></param>
/// <returns></returns>
private string Url_自动识别(string Text)//网络上找到
{
//用正则表达式识别URL超链接http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
Regex UrlRegex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
//用正则来查询
MatchCollection matches = UrlRegex.Matches(Text);
foreach (Match match in matches)
{
Text = Text.Replace(match.Value, string.Format("<a href=\"{0}\" target=\"_blank\">{1}</a>", match.Value, match.Value));
}
//用正则表达式识别Email地址,和查询超链接一样
Regex EmailRegex = new Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
matches = EmailRegex.Matches(Text);
foreach (Match match in matches)
{
Text = Text.Replace(match.Value, string.Format("<a href=mailto:{0}>{1}</a>", match.Value, match.Value));
}
return Text;
}
/// 自动识别超链接
/// </summary>
/// <param name="Text"></param>
/// <returns></returns>
private string Url_自动识别(string Text)//网络上找到
{
//用正则表达式识别URL超链接http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
Regex UrlRegex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
//用正则来查询
MatchCollection matches = UrlRegex.Matches(Text);
foreach (Match match in matches)
{
Text = Text.Replace(match.Value, string.Format("<a href=\"{0}\" target=\"_blank\">{1}</a>", match.Value, match.Value));
}
//用正则表达式识别Email地址,和查询超链接一样
Regex EmailRegex = new Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
matches = EmailRegex.Matches(Text);
foreach (Match match in matches)
{
Text = Text.Replace(match.Value, string.Format("<a href=mailto:{0}>{1}</a>", match.Value, match.Value));
}
return Text;
}
相关文章推荐
- wpf,能够复制文字 及自动识别URL超链接的TextBlock
- 在 wxWidgets 中使用 RichEdit 及超链接自动识别
- 自动识别输入的字符串并转换成可单击的超链接
- 自动识别超链接
- 自动识别内容中的Url并添加超链接
- 在 wxWidgets 中使用 RichEdit 及超链接自动识别
- 自动识别并加上超链接 JS来控制按钮上面的显示字。
- 自动识别超链接
- STM32ISP与STM32波特率自动识别技术理解
- 扫描二维码自动识别手机APP下载地址
- ColorSense for Xcode自动识别UICOLOR颜色并显示预览
- Excel超链接的应用-在Excel里输入身份证号,自动生成查找身份证信息的链接(可批量)
- 关于u-boot for MINI6410自动识别内存大小的原理
- Android 利用AutoCompleteTextView实现模糊搜索功能,搜索结果自动提示,识别拼音首字母并转汉字提示
- 网页正文抽取中的网页编码字符集自动识别最佳方案 .
- 实现网址的自动识别
- 中文人名自动识别的一种有效方法
- 动易多屏优化怎么实现网站自动识别用户访问设备
- 如何使用深度学习自动识别限速标志?这里有一份Keras和TensorFlow教程
- BytesEncodingDetect.java 自动识别文件编码