written this string to match all the test strings at once.
String="AQuickBrown_fox jump over the-lazy-Dog";
Basically I want to make these string look like this:
"a-quick-brown-fox-jump-over-the-lazy-dog"
I tried split("/regex/") function on string and applied join("-") function on the returned array and applied .toLowerCase. But I could not find the solution. I want to know the regular expression that could split the word so that i can get the required string.
3
Answers
From https://www.geeksforgeeks.org/how-to-convert-a-string-into-kebab-case-using-javascript/
This checks for space, capital letters, and underscores. It creates an array and pushes the words that separate the strings. Now join the array with the hyphen using the
join()
. After that convert the whole string into a lower case.I prefer more than one replace for readability
I will purloin the kebabCase name for this
Here’s a solution using replace function: