余志国网站设计工作室是专业从事义乌网站建设、义乌外贸网站建设、义乌网站制作、义乌网站设计的专业义乌网站建设工作室,是义乌外贸网站建设专家!

ASP截取网址URL中的顶级域名正则表达式

分类:程序开发 Tags: asp 截取 正则 函数 评论:1 浏览:5190 最近更新时间:2010/11/4 15:36:46

函数功能从提交的URL中提取顶级域名,失败返回空,注意要把可用的后缀全写到domext变量中。
 
  1. function durlck(url)
  2. domext="com|net|org|cn|co.kr|com.cn"
  3. durlck="" : url=lcase(url)
  4. if url="" or len(url)=0 then exit function
  5. url=replace(replace(url,"http://",""),"https://","")
  6. s1=instr(url,":")-1 '过滤掉端口
  7. if s1 < 0 then s1=instr(url,"/")-1 '过滤掉/后面的字符 
  8. if s1 > 0 then url=left(url,s1)
  9. Set re = new RegExp
  10. re.IgnoreCase = True : re.global = True
  11. re.Pattern = "([a-z0-9-]){1,63}\.(" & domext & ")(\:\d+)?$"
  12. Set Matches = re.Execute(url) 
  13. durlck = Matches(0)
  14. set re=nothing
  15. end function
 
  1. <%
  2. Function getDomain(domain)
  3.     Dim re,ReturnStr,Matches
  4.     Set re=new RegExp
  5.     re.IgnoreCase =True
  6.     re.Global=True
  7.     
  8.     re.Pattern = "(w+.(com.cn|net.cn|com|cn|net|org))"
  9.     Set Matches = re.Execute(domain)
  10.     ReturnStr = ""
  11.     For Each Match in Matches
  12.         ReturnStr = Match.Value
  13.         Exit for
  14.     Next
  15.     getDomain = ReturnStr
  16.     Set re=Nothing
  17. End Function
  18. response.write getDomain("http://www.yuzhiguo.com")
  19. %>

本文地址:/486/
  • 相关文章
  • 推荐文章
  • 最新文章
发表评论





您的IP:3.236.209.138,来自:
starshina2013
1. starshina2013 : 发挥中彩票,演奏于世界各地的你赢、 也可以参加环流,并从舒适的家里能赢 2013/7/8 18:21:00

留言

 


免费咨询
建站咨询热线
15967985565

扫一扫微信咨询
QQ: 358758308 Skype: yuzhiguo Facebook: yuzhiguo Email