自动识别HTML的标记 替换连接

时间:2021-12-26 08:26:06
  1. <%  
  2. Function SenFe_UbbCode(sContent)  
  3.     Dim TempReg  
  4.     Set TempReg = New RegExp  
  5.     With TempReg  
  6.         .IgnoreCase = True  
  7.         .Global = True  
  8.         '自动识别网址  
  9.         If InStr(Lcase(sContent),"http://")>0 Then  
  10.             .Pattern = "(^|[^<=""])(http:(\/\/|\\\\)(([\w\/\\\+\-~`@:%])+\.)+([\w\/\\\.\=\?\+\-~`@\':!%#]|(&)|&)+)"  
  11.             sContent = .Replace(sContent,"$1<a href=""$2"" target=""_blank"">$2</a>")  
  12.         End If  
  13.         '自动识别www等开头的网址  
  14.         If InStr(Lcase(sContent),"www.")>0 or InStr(Lcase(sContent),"bbs.")>0 Then  
  15.             .Pattern = "(^|[^\/\\\w\=])((www|bbs)\.(\w)+\.([\w\/\\\.\=\?\+\-~`@\'!%#]|(&))+)"  
  16.             sContent = .Replace(sContent,"$1<a href=""http://$2"" target=""_blank"">$2</a>")  
  17.         End If  
  18.     End With  
  19.     Set TempReg = Nothing  
  20.     SenFe_UbbCode = sContent  
  21. End Function  
  22. %>