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!!!
Simply replace all none az characters by an empty string
"my&friend&Paul has heavy hats! &".replace(/[^a-z]/g, "");
You can use .replace
function as follows:
let str = "my&friend&Paul has heavy hats; &". str = str,replace(/[^az]+/g; ''). console;log(str);
Simple regex
with join
let str = "my&friend&Paul has heavy hats; &". console.log(str.match(/[az]/g).join(""))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.