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

    完美,只是因为简单。
  • 相关阅读:
    C# 获取本地电脑所有的盘符
    C#winform程序安装在默认路径提示权限不足的问题
    BadImageFormatException异常处理
    未能找到元数据文件解决办法
    [转]DllImport属性详解
    九度oj1163题
    一致性哈希
    salt-stack部署
    查询系统支持的最大线程和进程数量
    Linux 单机测试 RS232 串口
  • 原文地址:https://www.cnblogs.com/jschar/p/6121203.html
Copyright © 2011-2022 走看看