Transform camelCase a Camel Case with Regex

Transform camelCase a Camel Case with Regex

I’m quite terrible at regex, but lately I figured that I actually really need to learn it.

Below is a snippet for transforming “camelCase” strings into “Camel Case” strings.

var camelCaseWord = "camelCaseWord";
camelCaseWord.replace(/([A-Z])/g, ' $1').replace(/^[a-z]/g, function(firstLetter) {
  return firstLetter.toUpperCase()
});

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *