PadProcessor.js
function(regex, text){
    var nextIndex = 0;
    var result = [];

    var execResult;
    while ((execResult = regex.exec(text))!== null) {
        result.push({
            start: execResult.index, 
            matchLength: execResult[0].length});
    }

    return {
        next: function(){
            return nextIndex < result.length ?
                result[nextIndex++] :
                null;
        }
    };
}
function(regex, text){
    var nextIndex = 0;
    var result = [];

    var execResult;
    while ((execResult = regex.exec(text))!== null) {
        result.push({
            start: execResult.index, 
            matchLength: execResult[0].length});
    }

    return {
        next: function(){
            return nextIndex < result.length ?
                result[nextIndex++] :
                null;
        }
    };
}
function ( regex , text ) { var nextIndex = 0 ; var result = [ ] ; var execResult ; while ( ( execResult = regex . exec ( text ) ) !== null ) { result . push ( { start : execResult . index , matchLength : execResult [ 0 ] . length } ) ; } return { next : function ( ) { return nextIndex < result . length ? result [ nextIndex ++ ] : null ; } } ; }
this is a convenience regex matcher that iterates through the matches
and returns each start index and length
@param {RegExp} regex
@param {String} text
this is a convenience regex matcher that iterates through the matches and returns each start index and length