Marcelo Mariussi
Marcelo Mariussi

Reputation: 11

Regex for price error

Im using the following regex code to get the price like R$ 59,00 and transform to only 59.

R\$ (\d+) insert $$1.

However for prices above R$ 999,00, like R$ 1.000,00 there is an extra ".", and for this example the result showing is 1. instead of 1000.

Maybe its because \d only work with numbers.

Anyway, im trying to find a solution for this but i couldnt find so far.

Does anyone have any idea how to fix this using regex ?

Picture of Regex Example with problem

Upvotes: 1

Views: 54

Answers (2)

shockawave123
shockawave123

Reputation: 697

Yes you are correct \dwill only get numbers. I don't think you can accomplish what you want with 1 regular expression.

Use R\$ ((?:\d+\.?)+) which would give you 1.000 Not Sure what language you are using, but you can then replace the "." with an empty string.

Upvotes: 1

Michele Pisani
Michele Pisani

Reputation: 14179

Try to use this regex:

R\$ [.0-9]+

Upvotes: 0

Related Questions