asp下正則實(shí)現(xiàn)URL自動(dòng)鏈接的一個(gè)函數(shù)
更新時(shí)間:2007年04月04日 00:00:00 作者:
復(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
相關(guān)文章
EditPlus中的正則表達(dá)式實(shí)戰(zhàn)(5)
這篇文章主要介紹了EditPlus中的正則表達(dá)式實(shí)戰(zhàn)(5)的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-12-12一個(gè)正則表達(dá)式導(dǎo)致CPU 利用率居高不下
這篇文章給大家?guī)?lái)了一個(gè)正則表達(dá)式導(dǎo)致CPU 利用率居高不下,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-06-06正則表達(dá)式限制 賬號(hào) 密碼 郵箱 身份證 手機(jī)號(hào)的相關(guān)代碼
這篇文章主要介紹了正則表達(dá)式限制 賬號(hào) 密碼 郵箱 身份證 手機(jī)號(hào)的相關(guān)代碼的相關(guān)資料,需要的朋友可以參考下2016-01-01正則匹配密碼只能是數(shù)字和字母組合字符串功能【php與js實(shí)現(xiàn)】
這篇文章主要介紹了正則匹配密碼只能是數(shù)字和字母組合字符串功能,涉及針對(duì)字符、數(shù)字等正則操作相關(guān)技巧,并給出了php與js實(shí)現(xiàn)示例,需要的朋友可以參考下2017-01-01Android 2018最新手機(jī)號(hào)驗(yàn)證正則表達(dá)式方法
這篇文章主要介紹了Android 2018最新手機(jī)號(hào)驗(yàn)證正則表達(dá)式方法,需要的朋友可以參考下2018-03-03