parsing css measures
<p>When i write a jQuery plugin i like to specify options for spacings the CSS way.
I wrote a function that returns a CSS String as values in a object. </p>

<p>5px 10px returns top: 5px, right: 10px, bottom: 5px, left: 10px</p>

<p>Now i often use the returned values to do some calculations and its not very nice to have to extract the measuring unit every time...</p>

<p>I suck in writing regular expressions could someone help me complete this function:</p>

<pre><code>this.cssMeasure = function(cssString, separateUnits){

    if ( cssString ){
        var values = {}
    }else{
        return errorMsg
    }

    var spacing = cssString.split(' ')
    var errorMsg = 'please format your css values correctly dude'

    if( spacing[4] ) {
        return errorMsg
    } else if ( spacing[3] ) {
        values = {top: spacing[0], right:spacing[1], bottom:spacing[2], left:spacing[3]}
    } else if ( spacing[2] ) {
        values = {top: spacing[0], right:spacing[1], bottom:spacing[2], left:spacing[1]} 
    } else if ( spacing[1] ) {
        values = {top: spacing[0], right:spacing[1], bottom:spacing[0], left:spacing[1]}
    } else {
        values = {top: spacing[0], right:spacing[0], bottom:spacing[0], left:spacing[0]}
    }

    if (separateUnits) {
        $.each(values, function(i, value){
            /*
             at this place i need to extract the measuring unit of each value and return them separately
             something like top: {value: 10, unit: 'px'}, right: {bla} and so on
            */
        })
    }

    return values

}
</code></pre>

<p>if you have any idea how to improve this function i am open to your comments.</p>
