Last active
September 17, 2015 08:19
-
-
Save leifoolsen/31db7e09203058c68dc5 to your computer and use it in GitHub Desktop.
Split a string into a numeric value and a trailing char sequence
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
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