python - how to write regex for a price expression? -
expression : "price(might contain comma) eg"
examples:
40 eg or
4,657 eg or
4,352,345 eg i want 1 string regex should use of these cases.
you try one:
^\d{1,3}(,\d{3})*\seg$ if want decimals well...
^\d{1,3}(,\d{3})*(\.\d\d?)?\seg$ now, if can have numbers (more 999) without commas @ , possible decimal...
^\d{1,3}(,?\d{3})*(\.\d\d?)?\seg$ more details:
^ @ start means price must start next character (here \d meaning numeric character)
\d{1,3} means 1 3 numeric characters.
(,\d{3})* group, appearing 0 times or more, consisting of comma , 3 numeric characters. assuming price 'clean', things ,34 in price 3,34 eg won't allowed through.
(\.\d\d?)? group, appearing 0 or 1 time, consisting of period ., digit , second possible digit. things .2 or .54 allowed. .564 not, however.
\s means 1 space character, , no more, no less. if price data given 'clean', there should no issue , identify not 'clean'.
eg matches currency eg.
$ means preceding character (g in case) has last one.
Comments
Post a Comment