[해결로 표시] 케밥 케이스를 스네이크 케이스로 교체(밑줄이 있는 대시)

  

2
주제 스타터

I need to create a function in javascript which will replace

kebab case (dashes: "-")

with

snake cased version (underscore dash "_")

in a string.

1개 답글
2

Here you go (with replace and regex):

function kebabToSnake(str) {
    //replace all dashes with
    var myString = str.replace(/-/g, "_");
    //return str
    return myString;
    //try with: "this - is -a - ---test";
}
공유: