Get HTML5 origin


/ Published in: Regular Expression
Save to your folder(s)

Use this to extract an HTML5 origin from a URI. $1 is the origin.

The square brackets are there to support IPv6 addresses.

Example:

var html5OriginRegex = /^([\w-]+:\/*\[?[\w\.:-]+\]?(?::\d+)?).*/;
"http://www.google.com:42/foo/bar/baz.html".replace(html5OriginRegex, "$1")
== "http://www.google.com:42"


Copy this code and paste it in your HTML
  1. /^([\w-]+:\/*\[?[\w\.:-]+\]?(?::\d+)?).*/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.