Created
July 9, 2015 13:02
-
-
Save s22su/5fb2528dffc25e7d413d to your computer and use it in GitHub Desktop.
Capitalize names
This file contains hidden or 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
| // 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