asp下用正規實作字串中的網址加連結的程式碼<%
'字段內網址加上聯結。
Function ToLink(Str)
Dim RE '正規表示式物件Dim strContent
If IsNull(Str) Then Str =
Set RE = New RegExp '建立正規表示式對象
With RE
.Global = True '搜尋應用於整個字串
.IgnoreCase = True '搜尋不區分大小寫的
strContent = Str
'************************************************* **************
'郵件地址連結自動設定
'************************************************* **************
.Pattern = ([/w]*)@([/w/.]*)
strContent = .Replace(strContent, <A Href='mailto:$1@$2'>$1@$2</A> )
'************************************************* **************
'連結自動設定
'************************************************* **************
'======根據要求再新增協定名稱=======
Dim D(3), I
D(0) = http
D(1) = ftp
D(2) = news
D(3) = mms
'===================================
For I = 0 To UBound(D)
.Pattern = D(I) + :////([/w/.]*)
strContent = .Replace(strContent, <A Href=' + D(I) + ://$1' target=_blank> + D(I) + ://$1</A> )
Next
'************************************************* **************
End With
Set RE = Nothing
ToLink = strContent
End Function
%>