Obrázek SVG
[#T#]
According to http://www.w3.org/TR/css3-values/#ltnumbergt , "A number can either be an integer, or it can be zero or more digits followed by a dot (.) followed by one or more digits", in regexp language\d+|\d*\.\d+ Let's add an optional sign to it, and make the group "non-capturing" to make the parsing simpler([+-]?(?:\d+|\d*\.\d+)) Enumerating all possible units is tedious.
Therefore let the unit be any sequence of lowercase letters (including none) or a percent sign([a-z]*|%) Putting it all together,propRe = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/ When you apply this to a value parts = "+12.34em".match(propRe) the numeric value will be in parts[1] and the unit in parts[2]share edit follow flag answered Apr 19 '10 at 23:10user18729149.6k1818 gold badges8787 silver badges127127 bronze badgesadd a comment