Search code examples
regexstringcoldfusion

How can I convert camelCase to a string with spaces? (e.g. camelCase to "Camel Case")


Using ColdFusion, I'd like to convert camelCase strings into a human readable string, like:

firstName -> First Name

Also, this will ideally be done all inline, with something like Ucase(rereplace('myCamelCaseString',[regex]," ")). If inline is not possible, then a UDF perhaps?


Solution

  • #rereplace("camelCaseString","([A-Z])"," \1","all")#

    edit: the version below will handle the lowercase first character.

    #rereplace(rereplace("camelCaseString","(^[a-z])","\u\1"),"([A-Z])"," \1","all")#