/ Published in: ActionScript 3
Expand |
Embed | Plain Text
// with protocol var url:String = "http://www.domain.com/?value=test&message=debug"; var reg:RegExp = /([a-z]*:\/\/)?([a-z-_]*)?.?[a-z-_]*.[a-z]*/; trace(url.match(reg)[0]); // http://www.domain.com // without base protocol var url:String = "http://www.domain.com/?value=test&message=debug"; var reg:RegExp = /[^https:\/\/]([a-z-_]*)?.?[a-z-_]*.[a-z]*/; trace(url.match(reg)[0]); // www.domain.com
Comments
Subscribe to comments
You need to login to post a comment.

static private const URLREGEXP:RegExp = /(https?:\/\/[-\w.]+)+(:\d+)?(\/([\w\/.]*(\?\S+)?)?)?/
static public function getHost(url:String):String { var results:Array = url.match(URLREGEXP); return results ? url.match(URLREGEXP)[1] : null; }
I use this functions to extract the URL and make all relative paths to absolute (sometimes I need to)