Convert a string to camel case notation with regex - Node.js Regular expression

Node.js examples for Regular expression:Match

Description

Convert a string to camel case notation with regex

Demo Code


/**/*ww w.j ava 2  s .co m*/
 * Convert a string to camel case notation.
 * @param  {String} str String to be converted.
 * @return {String}     String in camel case notation.
 */

exports.camelCase = function(str) {
  return str.replace(/[_.-](\w|$)/g, function(_, x) {
    return x.toUpperCase();
  });
};

Related Tutorials