I'm trying to remove the fullstops, commas and spaces from a string. I'm pretty sure I have to do this using this: str.replace(<some Regex here>, "");
I'm just not very familiar with Regex, how can I accomplish this?
Use this regex /[.,\\s]/g
var str = 'abc abc a, .aa '; var regex = /[.,\\s]/g; var result = str.replace(regex, ''); document.write(result);
You don't need to escape character except ^-]\\
in character class []
Any character except ^-]\\ add that character to the possible matches for the character class.
我相信这应该做到:
str.replace(/[.,\s]/g, '');
像这样的东西应该工作......
str=str.replace(/./g,'').replace(/,/g,'').replace(/ /g,'');
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.