user3297547 user3297547 - 4 months ago 18x
Javascript Question

jQuery - replace multiple currency symbols from string

I hope this question isn't too basic.

I have a strings like

  1. "$1.11"

  2. "£1.50"

  3. "15,16 €"

Is it possible to remove the currency symbols like
character from the string within single
string.replace('$', '');

I don't want to use multiple cases or switch case.

var str = "$1.00, £2.00, €3.00";
var newStr = str.replace(/[\$£€]/g, '');

As you can see, you can use a regex expression to remove all the symbols.

It currently replaces $, £, and € - but if there are others you can add each individual symbol between the [square brackets]