using regex to remove $ sign

John Machin sjmachin at lexicon.net
Tue Apr 11 05:38:19 EDT 2006


bearophileHUGS at lycos.com wrote:
> Fredrik Lundh>RE?  ex-perler?  try strip+lstrip instead:<
>
> Or even:
> >>> text = "  $12921  "
> >>> text.replace("$", "")
> '  12921  '

That's fair enough with the given input, but it would silently swallow
the "$"  in "123$5678" --  this sort of approach leads to all sorts of
disasters. The next problem after you've got rid of the $ is that
you'll find commas in it. No worries, we'll just rip out any commas
too!! So what happens is this: punter is thinking twelve dollars and 34
cents but types in 12,34 either because he's European or (more likely)
because he made a typo (comma is next to period on most folks
keyboards) then some twit programmer blindly rips out the comma and hey
presto you've got twelve hundred and 34 dollars. Think it's unlikely?
Just check out the bidding bidding on a certain large well-known online
auction system :-)




More information about the Python-list mailing list