Skip to content

Instantly share code, notes, and snippets.

@s22su
Created July 9, 2015 13:02
Show Gist options
  • Select an option

  • Save s22su/5fb2528dffc25e7d413d to your computer and use it in GitHub Desktop.

Select an option

Save s22su/5fb2528dffc25e7d413d to your computer and use it in GitHub Desktop.
Capitalize names
// from http://stackoverflow.com/questions/6251463/regex-capitalize-first-letter-every-word-also-after-a-special-character-like-a
var re = /(\b[a-z](?!\s))/g;
var s = "fort collins, croton-on-hudson, harper's ferry, coeur d'alene, o'fallon, MARI-ANN, KARL BRT TUAS";
s = s.toLowerCase().replace(re, function(x){return x.toUpperCase();});
console.log(s); // "Fort Collins, Croton-On-Hudson, Harper's Ferry, Coeur D'Alene, O'Fallon"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment