Converting any string into camel case
How can I convert a string into camel case using javascript regex? EquipmentClass name or Equipment className or equipment class name or Equipment Class Name should all become: equipmentClassName . CMS Looking at your code, you can achieve it with only two replace calls: function camelize(str) { return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) { return index == 0 ? word.toLowerCase() : word.toUpperCase(); }).replace(/\s+/g, ''); } camelize("EquipmentClass name"); camelize("Equipment className"); camelize("equipment class name"); camelize("Equipment Class Name"); // all output