Posted By

hejaaa on 04/06/11


Tagged

regexp name domain regular Expression


Versions (?)

Extract domain name with RegExp


 / Published in: ActionScript 3
 

  1. // with protocol
  2. var url:String = "http://www.domain.com/?value=test&message=debug";
  3. var reg:RegExp = /([a-z]*:\/\/)?([a-z-_]*)?.?[a-z-_]*.[a-z]*/;
  4. trace(url.match(reg)[0]); // http://www.domain.com
  5.  
  6. // without base protocol
  7. var url:String = "http://www.domain.com/?value=test&message=debug";
  8. var reg:RegExp = /[^https:\/\/]([a-z-_]*)?.?[a-z-_]*.[a-z]*/;
  9. trace(url.match(reg)[0]); // www.domain.com

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: burnandbass on April 11, 2011

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; }

    public static function decode(s:String):String {
        return unescape(s.replace(/\+/g, ' '))
    }   

I use this functions to extract the URL and make all relative paths to absolute (sometimes I need to)

You need to login to post a comment.