Reputation: 123
How can I remove £
from a string. I was trying this:
price = data.salesPrice;
price = price.replace(/\^£/,"");
console.log(price);
but still I was receiving like this: £22.80
. I tried with parseInt
but it's return NaN
. Any idea please ?
Upvotes: 1
Views: 1065
Reputation: 47966
I am assuming (from your regex attempt) that your objective here is to remove the pound symbol (
£
) from the beginning of a string.
You are escaping the caret symbol in your regex. This means you want to match a literal ^
and not use it to indicate the beginning of a string. Remove that escaping and your regex will work as expected.
price = price.replace(/^£/,"");
Upvotes: 5
Reputation: 19049
I'd go with regexp removing all the other characters except numbers (and dot):
var price = "£22.80";
price = price.replace(/\D*/, "")
Upvotes: 5
Reputation: 15393
Try
price = "£22.80";
price = price.replace("£" ,"");
console.log(price);
Upvotes: 0