zoukankan      html  css  js  c++  java
  • 正则表达式解析URL

    正则表达式:

    var match = /^((ht|f)tps?:)//([w-]+(.[w-]+)*/){1}(([w-]+(.[w-]+)*/?)*)?(?([w-.,@?^=%&:/~+#]*)+)?$/;
    /* 
    注:
    (1)、如需允许其他联接方式,可以修改“(ht|f)tps?”部分,在“?”后面跟上符号“|”,然后加上您需要的联接方式,多个时用符号“|”分隔)。
    (2)、如需允许URL参数包含其它字符,可以修改“[w-.,@?^=%&:/~+#]”,以设置您需要的参数。
    */

    匹配(说明):

    var matchString = 'http://www.cnblogs.com/jschar/index.html?auther=jschar&date=2016-10-01';
    console.log(match.exec(matchString));
    /*
        [0]: "http://www.cnblogs.com/jschar/index.html?auther=jschar&date=2016-10-01"
        [1]: "http:" ==> window.document.location.protocol
        [2]: "ht"
        [3]: "www.cnblogs.com/" ==> window.document.location.host 或 window.document.location.hostname
        [4]: ".com" ==> 域名后缀名
        [5]: "jschar/index.html" ==> window.document.location.pathname
        [6]: "index.html" ==> 当前页面名称
        [7]: ".html" ==> 当前页面后缀名
        [8]: "?auther=jschar&date=2016-10-01" ==> window.document.location.search
        [9]: "auther=jschar&date=2016-10-01" ==> 当前页面的所有参数
    */
    
    

     使用说明:

    (1)、地址必须以http/https/ftp/ftps开头;

    (2)、地址不能包含双字节符号或非链接特殊字符。

    完美,只是因为简单。
  • 相关阅读:
    Project 01 PlantAndZomb
    iOS平台内存使用原则
    IOS之UIKit_Day22--23
    IOS之UIKit_Day21
    IOS之UIKit_Day20
    浅谈javascript数据类型,对象,类
    从输入一个url到加载页面发生了什么?
    d3.js(2)-svg
    d3.js(1)
    console.time和performance.now()
  • 原文地址:https://www.cnblogs.com/jschar/p/6121203.html
Copyright © 2011-2022 走看看