Theres gotta be a simpler way of writing this, right?

Theres gotta be a simpler way of writing this, right?
0

#1

function onlySmallLetters(str) {
var removeNumbers = str.replace(/\d/g, “”);
var removeSpaces = removeNumbers.replace(/\s/g, “”);
var removeSymbols = removeSpaces.replace(/\W/g, “”);
var removeUnderScore = removeSymbols.replace(/[_]/g, “”);
return (removeUnderScore.toLowerCase());
}

Is there a way to compact these RegExp into one line?


#3

DOOOOHHH!!!

Ahh do I feel dumb :stuck_out_tongue:
Funny thing is that before writing that large block of code, I typed:

str.replace(/[1234567890!@#$%^&*()_±=[];’,./?><|":}{]/g)

but the slashes and brackets were breaking it so I searched W3 school’s site to learn about metacharacters … and I never thought to place them all in the square brackets like I initially tried out with all those charcters, SMH.