Nodejs URL Parse parseURL()

Here you can find the source of parseURL()

Method Source Code

/*//from   w  w  w.j  ava  2s .co  m
 Write a script that parses an URL address given in the format:
 [protocol]://[server]/[resource] and extracts from 
 it the [protocol], [server] and [resource] elements.
 Return the elements in a JSON object.*/

String.prototype.parseURL = function () {
    var string = String(this),
        url = {
            protocol: undefined,
            server: undefined,
            resource: undefined
        },
        regExUrlParse = /(\w{3,10}):\/\/([A-z.]+)\/(.+)/g,
        parsedArr = regExUrlParse.exec(string);

    url.protocol = parsedArr[1];
    url.server = parsedArr[2];
    url.resource = parsedArr[3];

    return url;
};

Related

  1. parseURL()
    String.prototype.parseURL = function() {
      return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=@]+/g, function(url) {
        return url.link(url);
      });
    };
    
  2. parseURL()
    String.prototype.parseURL = function() {
      return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function(url) {
        return url.link(url);
      });
    };
    
  3. parseURL()
    String.prototype.parseURL = function() {
      return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function(url) {
        return url.link(url);
      });
    };
    
  4. parseURL()
    String.prototype.parseURL = function() {
      return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function(url) {
        return url.link(url);
      });
    };
    String.prototype.parseUsername = function() {
      return this.replace(/[@]+[A-Za-z0-9-_]+/g, function(u) {
        var username = u.replace("@","")
        return u.link("http://twitter.com/"+username);
    ...
    
  5. parseURL()
    String.prototype.parseURL = function() {
      return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(url) {
        return url.link(url);
      });
    };
    
  6. parseURL()
    String.prototype.parseURL = function() {
        return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function(url) {
            return url.link(url);
        });
    };