I have a code:
this.valor = String(this.valor).replace(/R\$/, '');
this.valor = String(this.valor).replace(/,/g, '');
this.valor = String(this.valor).replace(/\./g, '');
Example: put R$1.000,00
and return 100000
How to convert in a one line?
You could try something like this, however, I don't feel like I should suggest you to go down this path.
Blindly stripping ,
and .
out might lead to wrong data, it seems like you are parsing a currency here and $1.000,00
doeesn't necessarily equal to 100000
const sanitize = (string) => string.replace(/[R$.,]/g, ''); console.log(sanitize('R$1.000,00'));
Simply use " | " between regular expressions to combine them. As for solution Hitmands answer is recommended
console.log("R$1.000,00".replace(/\.|R\$|\,/g,''))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.