asp下正則實(shí)現(xiàn)URL自動(dòng)鏈接的一個(gè)函數(shù)
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
[code]Function AutoLinkURLs(strString)
Dim match, matches, offset, url, email, link, relnkAutoLinkURL relnkAutoLinkURL = "[[%URLText%]]" If Not IsObject(regExp) Then Set regExp = New RegExp regExp.Global = True regExp.IgnoreCase = True 'Look for URLs regExp.Pattern = "(((ht│f)tps?://)│(www\.))([\w-]+\.)+[\w-:]+(/[\w- ./?%#;&=]*)?" Set matches = regExp.Execute(strString) offset = 0 For Each match in matches url = match If Left(url, 4) = "www." Then url = "http://" & url link = Replace(Replace(relnkAutoLinkURL, "[[%URLText%]]", match), "[[%URL%]]", url) strString = Mid(strString, 1, match.FirstIndex + offset) & link & Mid(strString, match.FirstIndex + 1 + match.Length + offset, Len(strString)) offset = offset + Len(link) - Len(match) Next 'Look for emails regExp.Pattern = "[A-Za-z0-9_+-.']+@\w+([-.]\w+)*\.\w+([-.]\w+)*" Set matches = regExp.Execute(strString) offset = 0 For Each match in matches email = match link = Replace(Replace(relnkAutoLinkURL, "[[%URLText%]]", match), "[[%URL%]]", "mailto:" & email) strString = Mid(strString, 1, match.FirstIndex + offset) & link & Mid(strString, match.FirstIndex + 1 + match.Length + offset, Len(strString)) offset = offset + Len(link) - Len(match) Next AutoLinkURLs = strString End Function [/code] 該文章在 2013/7/28 9:22:37 編輯過(guò) |
關(guān)鍵字查詢(xún)
相關(guān)文章
正在查詢(xún)... |