Reputation:
The input string is - "my&friend&Paul has heavy hats! &"
.
And I want to get rid of everything except lowercase letters like:
"myfriendaulhasheavyhats"
I split it and applied the toLowerCase()
method, but it doesn't work with special characters. Need some help!!!
Upvotes: 1
Views: 567
Reputation: 28414
You can use .replace
function as follows:
let str = "my&friend&Paul has heavy hats! &";
str = str.replace(/[^a-z]+/g, '');
console.log(str);
Upvotes: 1
Reputation: 301
Simply replace all none a-z characters by an empty string
"my&friend&Paul has heavy hats! &".replace(/[^a-z]/g, "");
Upvotes: 3
Reputation: 1
Simple regex
with join
let str = "my&friend&Paul has heavy hats! &";
console.log(str.match(/[a-z]/g).join(""))
Upvotes: 0