Created
November 20, 2014 22:32
-
-
Save bradparker/3d8bbdbfc6dede975d13 to your computer and use it in GitHub Desktop.
Unit Matcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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