Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I replace commas in a string [closed]

Tags:

python

regex

I want to remove all commas from a string using regular expressions, I want letters, periods and numbers to remain just commas

like image 620
jimstandard Avatar asked Sep 08 '11 20:09

jimstandard


1 Answers

Why a regex?

mystring = mystring.replace(",", "")

is enough.

Of course, if you insist:

mystring = re.sub(",", "", mystring)

but that's probably an order of magnitude slower.

like image 165
Tim Pietzcker Avatar answered Sep 18 '22 12:09

Tim Pietzcker