Regular Expression to get the size value of a CSS property?
- by thiesdiggity
I wrote a regular expression to get the size from a CSS property:
/(([+-]?\d*\.?\d+(\s)*(px|em|ex|pt|in|pc|mm|cm)?)|thin|medium|thick)(\s|;|$)/i
but for some reason its not working as intended. For example, when I run the following:
preg_match_all('/(([+-]?\d*\.?\d+(\s)*(px|em|ex|pt|in|pc|mm|cm)?)|thin|medium|thick)(\s|;|$)/i',
"border-bottom:1px solid #99999;", $matches);
It outputs:
1px
99999;
But I only want the 1px value returned.
I understand why its returning the above but can't seem to figure out how to only return the size and not the color value. I tried using the following negative lookbehind but it's not working either:
/(((?<!#\d{3}|#\d{6})[+-]?\d*\.?\d+(\s)*(px|em|ex|pt|in|pc|mm|cm)?)|thin|medium|thick)(\s|;|$)/i
I want to use preg_match_all for those CSS properties that can have multiple size values (i.e. margin).
Anyone have any ideas how to get this regex to return only the size values?
Thanks for your help!