Skip to content

Instantly share code, notes, and snippets.

@bgauryy
Created September 9, 2018 12:40
Show Gist options
  • Select an option

  • Save bgauryy/5320065aa9c4195239eb0b1474649ebb to your computer and use it in GitHub Desktop.

Select an option

Save bgauryy/5320065aa9c4195239eb0b1474649ebb to your computer and use it in GitHub Desktop.
const IPV4Reg = '((([0-9])|(1*[0-9][0-9])|(2[1-4][0-9])|(25[0-5]))\\.){3}(([0-9])|(1*[0-9][0-9])|(2[1-4][0-9])|(25[0-5]))';
const IP4 = `(^${IPV4Reg}$)|(^${IPV4Reg}\\:)|(^${IPV4Reg}\/)`;
function getIPDomain(url) {
const matches = new RegExp(IP4).exec(url);
if (matches && matches[0]) {
return matches[0].replace(/\:|\//, '');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment