Skip to content

Instantly share code, notes, and snippets.

@andrienko
Created March 18, 2014 12:13
Show Gist options
  • Save andrienko/9618893 to your computer and use it in GitHub Desktop.
Save andrienko/9618893 to your computer and use it in GitHub Desktop.
sanitize string to look more like identifier. Numberless.
String.prototype.sanitize = function(){
return this.replace(/[^a-zA-Z]/g,'_').replace(/_{2,}/g,'_').toLowerCase().replace(/^_+|_+$/g,'');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment