简体   繁体   English

如何加入三个正则表达式

[英]How to join three regexp

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示例:投入R$1.000,00并返回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.你可以尝试这样的事情,但是,我觉得我不应该建议你沿着这条路走 go。

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 out 可能会导致错误的数据,似乎您在这里解析货币并且$1.000,00不一定等于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至于解决方案,建议使用 Hitmands 答案

 console.log("R$1.000,00".replace(/\.|R\$|\,/g,''))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM