Skip to content

Instantly share code, notes, and snippets.

@gogones
Forked from youssman/regex-camelCase-to-dash.js
Created December 5, 2020 14:51
Show Gist options
  • Save gogones/213243bf26dff75301664fef633c8f2a to your computer and use it in GitHub Desktop.
Save gogones/213243bf26dff75301664fef633c8f2a to your computer and use it in GitHub Desktop.
Javascript convert camelcase to dash (hyphen)
function camelCaseToDash( myStr ) {
return myStr.replace( /([a-z])([A-Z])/g, '$1-$2' ).toLowerCase();
}
var myStr = camelCaseToDash( 'thisString' );
alert( myStr ); // => this-string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment