Skip to content

Instantly share code, notes, and snippets.

@bradparker
Created November 20, 2014 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradparker/3d8bbdbfc6dede975d13 to your computer and use it in GitHub Desktop.
Save bradparker/3d8bbdbfc6dede975d13 to your computer and use it in GitHub Desktop.
Unit Matcher
// Take "3mm", "-3inches", or "3.45 cm" and return ['3', 'mm'], ['-3', 'inches'], ["3.45", "cm"] etc
function unitParse (str) {
return (str.match(/([-\d.]+)\s+?([A-Za-z]+)/) || []).slice(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment