Skip to content

Instantly share code, notes, and snippets.

@eligrey
Last active April 23, 2021 18:57
Show Gist options
  • Save eligrey/574682 to your computer and use it in GitHub Desktop.
Save eligrey/574682 to your computer and use it in GitHub Desktop.
origin regex for javascript
// Origin regex
const origin = /^[\w-]+:\/*\[?[\p{L}\d\\.:_-]+\]?(?::\d*)?/u;
"http://[::1]:234/foo?bar#baz".match(origin)[0] === "http://[::1]:234";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment