Hey I'm trying to figure out a regular expression to do the following.
Here is my string
I need to split this string by the comma's. Though due to the comma's used in the numerical data fields the split doesn't work correctly. So I want to remove the comma's in the numbers before running splitting the string.
new_string = re.sub(r'"(\d+),(\d+)"', r'\1.\2', original_string)
This will substitute the
, inside the quotes with a
. and you can now just use the strings split method.
>>> from StringIO import StringIO >>> import csv >>> r = csv.reader(StringIO('Place,08/09/2010,"15,531","2,909",650')) >>> r.next() ['Place', '08/09/2010', '15,531', '2,909', '650']