Skip to content

Instantly share code, notes, and snippets.

@davidicus
Last active January 10, 2018 16:25
Show Gist options
  • Save davidicus/396d0f57efe9b1a8805c8aed50d3f921 to your computer and use it in GitHub Desktop.
Save davidicus/396d0f57efe9b1a8805c8aed50d3f921 to your computer and use it in GitHub Desktop.
Separate camel/pascal case string into lead cap words
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