How to convert “camelCase” to “Camel Case”?

后端 未结 11 979
北荒
北荒 2020-11-27 10:25

I’ve been trying to get a JavaScript regex command to turn something like \"thisString\" into \"This String\" but the closest I’ve gotten is replac

11条回答
  •  孤街浪徒
    2020-11-27 11:01

    My version

    function camelToSpace (txt) {
      return txt
        .replace(/([^A-Z]*)([A-Z]*)([A-Z])([^A-Z]*)/g, '$1 $2 $3$4')
        .replace(/ +/g, ' ')
    }
    camelToSpace("camelToSpaceWithTLAStuff") //=> "camel To Space With TLA Stuff"
    

提交回复
热议问题