Home  >  Q&A  >  body text

javascript - Regular matching of whether the URL starts with double slashes + whether it contains a domain name + whether it contains a protocol

For example, I have four path conditions like this
'//img.xxx.com.cn/IKxOJF/qy_6/xm_22/20170426/e1475eedc6ff7dada35af3b8306f0a63.png';
'/IKxOJF/qy_6/xm_22/20170426 /e1475eedc6ff7dada35af3b8306f0a63.png';
'http://img.xxx.com.cn/IKxOJF/...';
'https://img.xxx.com.cn/IKxOJF...'
The first one starts with double slashes, and then it needs to automatically complete 'http:' or 'https:';
The second one needs to automatically complete the domain name http://img.xxx.com.cn ;
The third and fourth types are not operated.
How to write a regular pattern for such a match?

ringa_leeringa_lee2711 days ago501

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-05-19 10:32:41

    /^\/\//.test(str)

    reply
    0
  • Cancelreply