JSFiddle - React, Tailwind, and code Playground

by Michael Russell

JavaScript

var urlKey = '010203040506070809',
    css = 'background:green;color:pink;background:url(";background:pink;.png");color:pink;',
    url = css.match( /url\(.*?\)/ ),
    split,
    obj = {},
    i,tempObjKey,tempObjValue;

css = css.replace( url, urlKey );

split = css.split(';');

for( i = 0; i < split.length; i++ ) {
    split[i] = split[i].replace( urlKey, url );
}

for( i = 0; i < split.length; i++ ) {
    if( split[i].length > 0 ) {
        tempObjKey = split[i].match(/(.*?)(?=:)/)[0];
        tempObjValue = split[i].replace(tempObjKey+':','');
        if( obj.hasOwnProperty(tempObjKey) )
            obj[tempObjKey] += ' '+tempObjValue;
        else
            obj[tempObjKey] = tempObjValue;
}
}
alert( 'background: '+ obj.background +'\ncolor: '+ obj.color );