How to parse a URL?

前端 未结 6 596

If there is one thing I just cant get my head around, it\'s regex.

So after a lot of searching I finally found this one that suits my needs:

function         


        
6条回答
  •  隐瞒了意图╮
    2020-11-27 03:46

    There is a nice jQuery plugin for parsing URLs: Purl.

    All the regex stuff is hidden inside, and you get something like:

    > url = $.url("http://markdown.com/awesome/language/markdown.html?show=all#top");
    
    > url.attr('source');
    "http://markdown.com/awesome/language/markdown.html?show=all#top"
    
    > url.attr('protocol');
    "http"
    
    > url.attr('host');
    "markdown.com"
    
    > url.attr('relative');
    "/awesome/language/markdown.html?show=all#top"
    
    > url.attr('path');
    "/awesome/language/markdown.html"
    
    > url.attr('directory');
    "/awesome/language/"
    
    > url.attr('file');
    "markdown.html"
    
    > url.attr('query');
    "show=all"
    
    > url.attr('fragment');
    "top"
    

提交回复
热议问题