jschar

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

 

分类:

技术点:

相关文章:

  • 2021-10-09
  • 2021-09-02
  • 2022-12-23
  • 2021-11-27
  • 2022-02-04
  • 2022-12-23
猜你喜欢
  • 2021-11-24
  • 2021-11-14
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2021-05-21
  • 2021-06-25
相关资源
相似解决方案