I am trying to match the currency format xxx.xxx.xxx,xx
, here are some examples of the formats that would be valid:
29.332.893,32
-29.332.893,32 // Podrían ser numero negativos
29.332.893,322313213123132
00
00,1212
394458,92 // Nótese que los puntos son opcionales
I have this Regex:\b[0-9]+(([\\.][0-9]{3})*([\\,][0-9]+)*)*\b
The problem is that in the following list it matches values that I am NOT interested in matching:
10.98,09 // Matchea el 10 por un lado y 98,09 por el otro
10.980456 // Matchea el 10
00.2da02 // Matchea el 00
4,098.09 // Matchea 4,098 por un lado y 09 por el otro
121837182372133.321321313 // No debería matchear ya que los puntos es cada 3 numeros, ahora me matchea 121837182372133 por un lado, y 321321313 por el otro
I've been searching but I can't find a way to match only the valid formats, since I'm using the Matcher and when the invalid formats appear I'm always left with data that shouldn't be considered.
NOTE
The amounts could appear in any way, for example, the list of valid formats that I put above could appear like this (These are just some examples) :
total: $ 29.332.893,32 // Con el signo y espacios
tosdaasdtal: -29.332.893,32
tosdaasdtal: 29.332.893,32 // Sin el signo pesos
total: 29.332.893,322313213123132 asasasaasdasd
to333tal: $00
toastal: $00,1212
total: $ 00
394458,92 // Solo
From already thank you very much.
There are 2 valid formats:
Without thousands separator:
With dots as thousands separator:
That is, putting both expressions together:
And, since the number can be in any position in the text, we will make sure that it is not surrounded by another number, neither a period and a number, nor a comma and a number.
nor preceded by:
nor happened by:
Regular phrase
Code:
Result:
demonstration:
http://ideone.com/91hay3