/**
 *	textMonster 1.0.0
 *	by Mark Christian
 *	http://markchristian.org/projects/textmonster
 *
 *	textMonster is licensed under a Creative Commons
 *	Atttribution 3.0 license:
 *	http://creativecommons.org/licenses/by/3.0/
 */

  textMonster = function(regex) {
    
    //  Get matches
    var regExp = new RegExp(regex, "gm");
    var matchCount = 0;
    var matches = new Array();
    var matchInfo;
    while((matchInfo = regExp.exec(this.toString())) != null) {
      //  Match
      matches[matchCount++] = matchInfo[0];
    }
    
    //  Create textMonster object
    var returnValue = new textMonsterObject(matches);
    
    return returnValue;
    
  };

  function textMonsterObject(strings) {
    
    this.length = strings.length;
    this.strings = strings;
    
    this.count = function() {
      return this.strings.length;
    };
    
    this.each = function(eachFunction) {
      for(i in this.strings) {
        eachFunction(this.strings[i]);
      }
    }
    
    this.get = function(index) {
      return this.strings[index];
    };
    
    this.textMonster = function(regex) {
      var results = new Array();
      for(i in this.strings) {
        var tQ = this.strings[i].textMonster(regex);
        tQ.each(function(string) {
          results[results.length++] = string;
        });
      }
      
      return new textMonsterObject(results);
    };
    
  };
  
  String.prototype.textMonster = textMonster;