This mightbe a silly question, but I'm new to RegExes. I need a RegEx pattern for a price in my python program.
Sample cases :
8.00
25.14
271.61
2,367.82
52,124.09
9,37,159.82
Any help would be appreciated. Thanks in Advance.
This mightbe a silly question, but I'm new to RegExes. I need a RegEx pattern for a price in my python program.
Sample cases :
8.00
25.14
271.61
2,367.82
52,124.09
9,37,159.82
Any help would be appreciated. Thanks in Advance.
You are trying to match numbers formatted according to the rules of Indian numbering system. In order to do this correctly you have to carefully define what you would like to treat as a match. For example would string such as 100,10,100.00
constitute a match? You can find a validly formatted number inside this example, i.e. 10,100.00
but I assume that for your purposes string from the example should not match. I elaborated a bit on the tests and came up with this test suite:
# match
8.00
25.14
271.61
2,367.82
52,124.09
9,37,159.82
# don't match
9,378,159.82
9,37,159.820
12,.80
12,12
12.,12
12,12.80
10,80
.80
80,
Following regular expression passes these tests successfully.
(?<![\d,])((\d{1,2},)*\d{3}|(\d{1,3}))\.\d{2}(?!\d)