Skip to content

Instantly share code, notes, and snippets.

@MentalGear
Last active July 25, 2021 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MentalGear/d718c93b9bb0f4f47d10c7a52b7c5832 to your computer and use it in GitHub Desktop.
Save MentalGear/d718c93b9bb0f4f47d10c7a52b7c5832 to your computer and use it in GitHub Desktop.
Regex: Get URL Network Protocol
// based upon:
// https://docs.microsoft.com/en-us/dotnet/standard/base-types/how-to-extract-a-protocol-and-port-number-from-a-url
const url = 'http://www.google.com/fwef://gerg';
const regex = /^(?<proto>\w+):/g;
const found = url.match(regex);
console.log(found);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment