Skip to content

Instantly share code, notes, and snippets.

@arcdev1
Last active May 1, 2016 04:38
Show Gist options
  • Save arcdev1/8d982f6ae977efc44e801456d66043d3 to your computer and use it in GitHub Desktop.
Save arcdev1/8d982f6ae977efc44e801456d66043d3 to your computer and use it in GitHub Desktop.
var s = "some_string_to_change",
result = s.replace(/_./g, rep); // do a global search (g) for an "_" followed by a single character (.) and run the rep function each time
function rep(v) {
return v[1].toUpperCase(); // return the second character of the matched string, uppercased.
}
console.log(result);
@bensm1th
Copy link

bensm1th commented May 1, 2016

I got as far as:

function up_case(str2){
return str2.replace(/_./g,'');
}

But, I didn't know you could pass in a function for the new value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment