首页  ·  知识 ·  云计算
利用正则表达式自动给Email地址和Url加上连接
佚名  http://eway51.org/http://eway51.org/Article    编辑:dezai  图片来源:网络
using System; using System.Text.RegularExpressions; namespace CommLayer { &

using System;

using System.Text.RegularExpressions;

 

namespace CommLayer

{

       ///

       /// 自动给邮件地址或email地址加上url

       ///

       public class HyperlinkUrl

       {

              private static Regex urlregex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)",

                     RegexOptions.IgnoreCase|RegexOptions.Compiled);

              private static Regex emailregex = new Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)",

                     RegexOptions.IgnoreCase|RegexOptions.Compiled);

             

              public HyperlinkUrl()

              {                  

              }

 

              ///

              /// 生成带连接的字符串

              ///

              /// 需要生成带连接地址的字符串

              /// 经过转换的字符串

              public static string GenHyperlinkUrl(string link)

              {

                     link = emailregex.Replace(link, "$1");

                     link = urlregex.Replace(link, "$1");

 

                     return link;

              }

       }

}

 

本文作者:佚名 来源:http://eway51.org/http://eway51.org/Article
CIO之家 www.ciozj.com 微信公众号:imciow
    >>频道首页  >>网站首页   纠错  >>投诉
版权声明:CIO之家尊重行业规范,每篇文章都注明有明确的作者和来源;CIO之家的原创文章,请转载时务必注明文章作者和来源;
延伸阅读