Skip to content

Instantly share code, notes, and snippets.

@mrandrewmills
Created April 30, 2015 02:16
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 mrandrewmills/1eb3f081bc7576208525 to your computer and use it in GitHub Desktop.
Save mrandrewmills/1eb3f081bc7576208525 to your computer and use it in GitHub Desktop.
JSLint vs. Regex, before and after
// before
phrase = phrase.replace(/[^a-zA-Z]/g, "");
// after
phrase = phrase.match(/[a-zA-Z]/g);
phrase = phrase.toString();
phrase = phrase.replace(/[,]/g, "");
@mrandrewmills
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment