JSFiddle - React, Tailwind, and code Playground

by sym3tri

HTML

Reg ex tests
<div id="output"></div>

JavaScript

var regexp = new RegExp('(https?://)?([^:/#?]*)([\/:#?].*)?$');

function out(msg) {
  document.querySelector('#output').innerHTML += '<br>' + msg;
}

function getHost(url) {
  regexp = new RegExp('(https?://)?([^:/#?]*)([\/:#?].*)?$');
  matches = regexp.exec(url);
  return matches[2];
}

out(getHost('http://foo.bar.com/blah/more/stuff?and=query&params=true'));
out(getHost('https://bar.cn?sdfa=fasdf'));
out(getHost('asdf.com'));

// fail
out(getHost('asdf blah'));
out(getHost('!!#$@$'));