Regex to split camel case

前端 未结 12 1851
逝去的感伤
逝去的感伤 2020-11-28 23:31

I have a regular expression in JavaScript to split my camel case string at the upper-case letters using the following code (which I subsequently got from here):



        
12条回答
  •  佛祖请我去吃肉
    2020-11-28 23:59

    Hi I saw no live demo , thanks @michiel-dral

    var tests =[ "camelCase",
                 "simple",
                 "number1Case2"]
    
    function getCamelCaseArray(camel) {
      var reg = /([a-z0-9])([A-Z])/g;
      return camel.replace(reg, '$1 $2').split(' ');
    }
    
    function printTest(test) {
    document.write('

    '+test + '=' + getCamelCaseArray(test)+'

    '); } tests.forEach(printTest);
    
    
    
      
        
        
      
    
      
      
    
    

提交回复
热议问题