BeesWax
BeesWax

Reputation: 112

remove specific characters using js regex

My question is how to make the three steps I use into one step; how do I combine these to just one?

Thank you!

var string = "1.4 Whatever";
var a = string.replace(/[0-9]/g,'');
var b = a.replace(/[\.]/g, '');
var c = b.replace(/ /g, '');

console.log(c);

Upvotes: 0

Views: 30

Answers (1)

Simon R
Simon R

Reputation: 3772

Just like this

var string = "1.4 Whatever";
var a = string.replace(/[0-9\. ]/g,'');

console.log(a);

Upvotes: 1

Related Questions