I want to convert my string(str) to spinal-case string. Please explain me that how regex is working differently. Upper line of code is working properly but another line of code is putting "-" many times.
str.split(/\s|(?=[A-Z])|_/g).join("-").toLowerCase();
// or
str.replace(/\s|(?=[A-Z])|_/g,"-").toLowerCase();