View Full Version : how can I split() a css size value ...
brothercake
05-05-2003, 07:03 PM
for example - "0.7em" or "13px" so that I end up with [0.7,'em'] and [13,'px'] respectively.
Any thoughts? This is frying my brain slightly ...
/([0-9]*(?:\.[0-9]*)?)([a-z%]+)/
liorean
05-05-2003, 07:19 PM
Does this work?sCss.split(/(?=[\d.]+)(?=\w+)/);
If not, how about simply:aCss=[parseFloat(sCss),sCss.replace(/^[\d.]+/,'')];
beetle
05-05-2003, 07:21 PM
Another thought
sCss.match( /^(.*)(px|pt|em|ex|%)$/ );
I think that would work
liorean
05-05-2003, 07:26 PM
Hmm, maybe this:aCss=/([\d.]+)(.+)/.exec(sCss);You'd also get a first value that is the join, but otherwise it should be a good catcher.
brothercake
05-05-2003, 07:28 PM
So many answers :) thanks all.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.