peterhpchen
10/28/2014 - 7:18 AM

easily get information from script

easily get information from script

getDetailFromScript = function(script, name) {
    var data = script.replace(/\s*=\s*/g, "=");
    var escapeSequence = ["\\", ".", "(", ")", "[", "]", "{", "}", "^", "$", "|", "*", "+", "?"];
    for(var key in escapeSequence) {
        name = name.replace(escapeSequence[key], "\\" + escapeSequence[key]);
    }
    var results = new RegExp(name + "=([^;]*)").exec(data);
    if(results === null) {
        return null;
    } else {
        return results[1];
    }
}; //end getDetailFromScript