parse URL with JavaScript or jQuery

后端 未结 5 1434
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 02:44

Ok lets say I have a URL

example.com/hello/world/20111020 (with or without the trailing slash). What I would like to do is strip from the url the domain example.com.

5条回答
  •  臣服心动
    2020-12-17 03:29

    I have created the following regular expression for URLs

    ^https?://(((0|([1-9][0-9]{0,1}))(\.(0|([1-9][0-9]{0,1}))){3})|([a-zA-Z]([a-zA-Z0-9$\-_@\.&+!*"\'\(\),]|(%[0-9a-fA-F][0-9a-fA-F]))*(\.([a-zA-Z]([a-zA-Z0-9$\-_@\.&+!*"\'\(\),]|(%[0-9a-fA-F][0-9a-fA-F]))*))*))(/|((/([a-zA-Z]([a-zA-Z0-9$\-_@\.&+!*"\'\(\),]|(%[0-9a-fA-F][0-9a-fA-F]))*))*))$
    

    It has been written for MySql - I am sure with a bit of fiddling you can get it you work for your needs.

    BTW - I took the idea from an RFC - The number escapes me at this moment

提交回复
热议问题