regex needed to strip out domain name

后端 未结 5 1039
终归单人心
终归单人心 2020-12-20 01:09

I need a regexp to strip out just the domain name part of a url. So for example if i had the following url:

http://www.website-2000.com

the bit I\'d want the

5条回答
  •  旧时难觅i
    2020-12-20 02:02

    r/^[^:]+:\/\/[^/?#]+//
    

    This worked for me.

    It will match any scheme or protocol and then after the :// matches any character that's not a / ? or #. These three characters, when they first occur in a URL, signal the end of the domain so that's were I end the match.

提交回复
热议问题