Diary - 2018.09.05

github logo ・1 min read

Regex is really great for finding and/or replacing things.

I have files named my-file-name.js or my_file_name.js
and want to change them to camelCase myFileName.js.

function toCamelCase(name) {
  // search for "-" or "_" followed by a character and replace it uppercased
  return name.replace(/[-_]([a-z])/gi, (_, char) => char.toUpperCase());


/ => starts the regex
[-_] => - or _
([a-z]) => all lowercase letters, captured in a group
/ => ends the regex
gi => search all occurencies, ignore case 
(_, char) => char.toUpperCase() => _ is the passed in complete match, don't need it;
return the capture group (= the letter after - or _) uppercased
twitter logo DISCUSS
Classic DEV Post from May 31 '19

Presentation Tips for Technical Talks

Presentation Tips for Technical Talks

miku86 profile image
Developer & Explorer with a passion for learning, coding, futurology and technology. - Compare yourself to who you were yesterday, not to who someone else is today.

Sore eyes?

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️