I have a string
var numb = "R$ 2000,15"
I would like to cut two last numbers and comma,and R$
with space, to get result => 2000
.
I tried with regex: (?!\d{1,5}),(?:\d{2})
and it takes result: R$ 2000
. So now I would like to remove R$ with space.
Any help?
Try this regex, it should do the trick:
/^R\$\s(\d+)((\,\d{2})?)$/
To use it, you can replace like this:
let result = myNumber.replace(/^R\$\s(\d+)((\,\d{2})?)$/, "$1");
Note that each group between parentheses will be captured by your regex for replacement, so if you want the set of numbers before the comma you should use the corresponding group (in this case, 1). Also note that you should not put your regex between quotes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With