user1638055
user1638055

Reputation: 492

JavaScript regex replace not working?

I have this JavaScript code:

var test123 = $('product-price-' + productId).innerHTML; // thats 26,00 €
var finalPrice = test123.replace(/[^\d.,]/, ""); 

Testing my regex here: http://www.regular-expressions.info/javascriptexample.html correctly returns me 26,00, exactly what I want. Why is it not working in my code? In my code it replaces nothing at all.

Thanks!

Upvotes: 0

Views: 1230

Answers (1)

Alex K.
Alex K.

Reputation: 175956

Escape the period and add g to make it global;

/[^\d\.,]/g

Upvotes: 2

Related Questions