Last active
January 10, 2018 16:25
-
-
Save davidicus/396d0f57efe9b1a8805c8aed50d3f921 to your computer and use it in GitHub Desktop.
Separate camel/pascal case string into lead cap words
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
const myString = 'thisIsMyStringFool'; | |
// find and separate words based off capital letter | |
const replacedString = myString.replace(/([A-Z])/g, ' &1'); | |
//capitalize first letter of first word if not already | |
replacedString.replace(/^./, st => str.toUpperCase()); | |
console.log(replacedString); | |
// output => This Is My String Fool |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment