SwitchUp SwitchUp Ranked Best Coding Bootcamps 2025

How to split camel case and add hyphen in JavaScript

Altcademy Team wrote on 7 February 2018

You can use the following regex.
var myStr = 'thisIsAString'; myStr.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase(); // -> "this-is-a-string"

Trusted by

Students and instructors from world-class organizations

Join the upcoming Cohort #111

Enroll for March 2nd, 2026