Saturday, February 2, 2013

[perl] parseUrl


sub parseUrlInput {
  #protocal://user:pass@subdomain.domain:port/pathA/pathB/file.ext?arg1=z&arg2=y#flagment
  #$VAR1 = 'protocal';
  #$VAR2 = 'user';
  #$VAR3 = 'pass';
  #$VAR4 = 'subdomain.domain';
  #$VAR5 = 'subdomain';
  #$VAR6 = 'domain';
  #$VAR7 = 'port';
  #$VAR8 = '/pathA/pathB/file.ext';
  #$VAR9 = '/pathA/pathB/';
  #$VAR10 = 'file.ext';
  #$VAR11 = 'arg1=z&arg2=y';
  #$VAR12 = 'flagment';
  return $_[0] =~ m,^(?:(\w+)://)?(?:(\w+):(\w+)@)?((?:([\w\.]+)\.)?(\w+\.(?:\w+)))(?::(\d+))?(([\w/%]*/)(\w+(?:\.\w+)?)?)?(?:\?([\w=&]+))?(?:#(\w+))?$, if($_[0]);
}

No comments:

Why You Don't LIKE My FaceBook Fanpage ?
×
blogger