Created
April 30, 2015 02:16
-
-
Save mrandrewmills/1eb3f081bc7576208525 to your computer and use it in GitHub Desktop.
JSLint vs. Regex, before and after
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
// before | |
phrase = phrase.replace(/[^a-zA-Z]/g, ""); | |
// after | |
phrase = phrase.match(/[a-zA-Z]/g); | |
phrase = phrase.toString(); | |
phrase = phrase.replace(/[,]/g, ""); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JSLint doesn't like having a regex with a negation character (i.e. ^) in it.
Sure, it takes more steps to say what you DO want rather than what you DON'T want . . . but maybe it is better in the long run to develop that habit of specificity.