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.


var html5OriginRegex = /^([\w-]+:\/*\[?[\w\.:-]+\]?(?::\d+)?).*/;
"".replace(html5OriginRegex, "$1")
== ""

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

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.