Let's say I have a string of text:
The quick brown fox jumped over 8 or 9 lazy dogs
How would you convert this to lower case hyphen-conjoined words like this?
the-quick-brown-fox-jumped-over-8-or-9-lazy-dogs
I assume it requires some kind of regex to convert it correctly?
str.replace(/ +/g, '-').toLowerCase();
Use \s
for a space character in a regular expression, add the g
flag so it replaces all occurrences, and call toLowerCase()
to make the string lowercase:
str.replace(/\s/g, "-").toLowerCase();
Or this: "the quick brown fox jumps over the lazy dog".split(" ").join("-");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With