Regex for dropping http:// and www. from URLs

前端 未结 4 903
一向
一向 2020-12-04 00:34

I have a bunch of urls like these.

  $urls = array(
    \'https://site1.com\',
    \'https://www.site2.com\',
    \'http://www.site3.com\',
    \'https://sit         


        
4条回答
  •  天命终不由人
    2020-12-04 01:03

    /^(https?:\/\/)?(www\.)?(.*)\/$/i
    

    And use what's on $3. Or, even better, change the first two parentheses to the non-capturing version (?:) and use what's on 1.

提交回复
热议问题