Skip to content

Instantly share code, notes, and snippets.

@leifoolsen
Last active September 17, 2015 08:19
Show Gist options
  • Save leifoolsen/31db7e09203058c68dc5 to your computer and use it in GitHub Desktop.
Save leifoolsen/31db7e09203058c68dc5 to your computer and use it in GitHub Desktop.
Split a string into a numeric value and a trailing char sequence
var reUnit = /([a-z]*|%)$/;
var value = "120px"
var numericValue = parseInt(value.phone, 10);
var unit = value.match(reUnit)[1] || 'px';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment