萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> asp編程 >> asp 獲取字符串中url地址函數

asp 獲取字符串中url地址函數

asp教程 獲取字符串中url地址函數
本文章提供了三款利用asp的正則獲取字符串中url地址自定義函數哦,三個方法的實現原理都是獲取以http開的url地址哦。
on error goto z

dim url,key,wwwname
url=request.servervariables("server_name")
if instr(url,".")>0 then
key=split(url,".")
wwwname=key(0)
wwwname=replace(wwwname,"http://","")
end if
response.write(wwwname)

 方法二

'vb.net:
public shared function isurl(byval strtmp as string) as boolean
on error goto z
dim objintpattern as new system.text.regularexpressions.regex( "^(http://|https教程://){0,1}[a-za-z0-9][a-za-z0-9-.]+[a-za-z0-9].[a-za-z]{2,}[43-176]*$")
return objintpattern.ismatch(strtmp)
z:
end function

private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
msgbox (isurl( "http://www.sohu.com"))
方法三

dim objintpattern
isurl = false
set objintpattern = new regexp
objintpattern.pattern = "^(http://|https://){0,1}[a-za-z0-9][a-za-z0-9-.]+[a-za-z0-9].[a-za-z]{2,}[43-176]*$"
objintpattern.global = true
isurl = objintpattern.test(strtmp)
set objintpattern = nothing
z:
end function

private sub command1_click()
msgbox isurl( "http://www.sohu.com")
end sub

copyright © 萬盛學電腦網 all rights reserved