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
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
-
re正则表达式练习
判断变量名是否符合要求import re names = ["name1","_name","2_name","...
[阅读全文]
-
-
常用前端相关知识
1.字符串.replace(正则, function(v,i,str){ return 'xxx' }) //...
[阅读全文]
-
-
-
-
网友评论