Barry Doyle Barry Doyle - 2 years ago 115
Javascript Question

JavaScript remove fullstop, comma and spaces from a string

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?

Answer Source

Use this regex /[.,\s]/g

var str = 'abc abc a, .aa ';

var regex = /[.,\s]/g;

var result = str.replace(regex, '');


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download