Closed lijon closed 3 years ago
Assuming it follows standard windows INI file format, this should work:
function parseINIString(data){ var regex = { section: /^\s*\[\s*([^\]]*)\s*\]\s*$/, param: /^\s*([^=]+?)\s*=\s*(.*?)\s*$/, comment: /^\s*;.*$/ }; var value = {}; var lines = data.split(/[\r\n]+/); var section = null; lines.forEach(function(line){ if(regex.comment.test(line)){ return; }else if(regex.param.test(line)){ var match = line.match(regex.param); if(section){ value[section][match[1]] = match[2]; }else{ value[match[1]] = match[2]; } }else if(regex.section.test(line)){ var match = line.match(regex.section); value[match[1]] = {}; section = match[1]; }else if(line.length == 0 && section){ section = null; }; }); return value; }
(found at https://stackoverflow.com/questions/3870019/javascript-parser-for-a-string-which-contains-ini-data)
Assuming it follows standard windows INI file format, this should work:
(found at https://stackoverflow.com/questions/3870019/javascript-parser-for-a-string-which-contains-ini-data)