1function parseProtocol(url) {
2 const parsedURL = /^(\w+)\:\/\/([^\/]+)\/(.*)$/.exec(url);
3 if (!parsedURL) {
4 return false;
5 }
6 console.log(parsedURL);
7 // ["https://developer.mozilla.org/en-US/docs/Web/JavaScript", "https", "developer.mozilla.org", "en-US/docs/Web/JavaScript"]
8
9 const [, protocol, fullhost, fullpath] = parsedURL;
10 return protocol;
11}
12
13console.log(parseProtocol('https://developer.mozilla.org/en-US/docs/Web/JavaScript'));
14// "https"
15