Where does the input string come from? If this is a safe source (i.e., not coming from the user), just use the regular expression to separate the .cSSrule and eval() parts of the rest - you have your complete associative array parsed and created for you.
Edit: you need to replace ; on , except for the last appearance:
input .replace(/^(.*)(?={)/, '') .replace(/;(?!(\s)*?})/g, ',') .replace(';', ''); myCss = eval(input);
source share