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)、地址不能包含双字节符号或非链接特殊字符。

    完美,只是因为简单。
  • 相关阅读:
    2-3-4 tree留坑
    CCPC final Cockroaches
    对拍模板
    使用cronolog按日期分割日志
    linux git 命了
    变量加减乘除运算
    根据pom标签修改
    根据符号获取字符
    shell循环字符串数组
    git ssh key配置
  • 原文地址:https://www.cnblogs.com/jschar/p/6121203.html
Copyright © 2011-2022 走看看