Posted By

Sephr on 03/29/09


Tagged

origin html5


Versions (?)

Get HTML5 origin


 / Published in: Regular Expression
 

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"
  1. /^([\w-]+:\/*\[?[\w\.:-]+\]?(?::\d+)?).*/

Report this snippet  

You need to login to post a comment.