Skip to content

Instantly share code, notes, and snippets.

@rocbear
Last active April 21, 2016 12:15
Show Gist options
  • Save rocbear/256264b14da6085da691714af718025d to your computer and use it in GitHub Desktop.
Save rocbear/256264b14da6085da691714af718025d to your computer and use it in GitHub Desktop.
Split number and unit
function splitValueAndUnit(combined) {
var groups = /(\d*\.?\d*)(.*)/;
return combined.match(groups).slice(1);
}
splitValueAndUnit('10px') // ["10", "px"]
splitValueAndUnit('30.75deg') // ["30.75", "deg"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment