C# 正则替换文本为超链接

Regex   regex   =   new   Regex(  
  @"(http:////([/w.]+//?)/S*)",  
  RegexOptions.IgnoreCase  
  |   RegexOptions.CultureInvariant  
  |   RegexOptions.IgnorePatternWhitespace  
  |   RegexOptions.Compiled  
  );  
  string   content   =   "http://www.bizsofts.com   http://www.bizsofts1.com   http://www.bizsofts2.com/abc";  
  content   =   regex.Replace(content,   "<a   href=/"$1/"   target=/"_blank/">$1</a>");  
  Console.WriteLine(content);  
   
  输出结果:  
  <a   href="http://www.bizsofts.com"   target="_blank">http://www.bizsofts.com</a>   <a  
    href="http://www.bizsofts1.com"   target="_blank">http://www.bizsofts1.com</a>   <a  
    href="http://www.bizsofts2.com/abc"   target="_blank">http://www.bizsofts2.com/ab  
  c</a>

 

 

 

你可能感兴趣的:(String,C#,regex)