主頁 > 知識庫 > asp下正則實現(xiàn)URL自動鏈接的一個函數(shù)

asp下正則實現(xiàn)URL自動鏈接的一個函數(shù)

熱門標(biāo)簽:Mysql連接數(shù)設(shè)置 Linux服務(wù)器 電子圍欄 銀行業(yè)務(wù) 團購網(wǎng)站 服務(wù)器配置 科大訊飛語音識別系統(tǒng) 阿里云

復(fù)制代碼 代碼如下:

Function AutoLinkURLs(strString)  
    Dim match, matches, offset, url, email, link, relnkAutoLinkURL  
    relnkAutoLinkURL = "a href=""[[%URL%]]"">[[%URLText%]]/a>"  
    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

您可能感興趣的文章:
  • 讓URL只允許一些字符的正則表達式
  • JS 正則表達式(學(xué)習(xí)筆記2)匹配網(wǎng)址url參數(shù)
  • javascript 獲取url參數(shù)的正則表達式(用來獲取某個參數(shù)值)
  • php 正則表達式提取網(wǎng)頁超級鏈接url的函數(shù)
  • 用Javascript正則實現(xiàn)url鏈接的解析類
  • php利用正則表達式取出圖片的URL
  • JS驗證URL函數(shù) 正則

標(biāo)簽:棗莊 衡水 廣元 江蘇 大理 衢州 萍鄉(xiāng) 蚌埠

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp下正則實現(xiàn)URL自動鏈接的一個函數(shù)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266