taking off the http or https off a javascript string

前端 未结 12 1584
面向向阳花
面向向阳花 2020-12-20 11:23

I have the following strings

http://example.com
https://example.com
http://www.example.com

how do i get rid of the http:// or

12条回答
  •  -上瘾入骨i
    2020-12-20 12:12

    var txt="https://site.com";
    txt=/^http(s)?:\/\/(.+)$/i.exec(txt);
    txt=txt[2];
    

    for parsing links without http/https use this:

    var txt="https://site.com";
    txt=/^(http(s)?:\/\/)?(.+)$/i.exec(txt);
    txt=txt[3];
    

提交回复
热议问题