i’m trying to use a regexp to arrange some text, with re.sub.
Let’s say it’s an almost csv file that I have to clean to make it totally csv.
I replaced all \t by \n doing :
t = t.replace("\n", "\t")
… and it works just fine. After that, I need to get some \t back to \n, for each of my CSV lines. I use for that this expression :
t = re.sub("\t(\d*?);", "\n\1;", t, re.U)
The problem is it works… but partially. The \n are added properly, but instead of being followed by my matching group, they are followed by a ^A (according to Vim)
I tried my regexp using a re.findall and it works juste fine… so what could be wrong according to you ?
My CSV lines are finally supposed to be like :
number;text;text;...;...;\n
Thanks for your help !
Your
\1is interpreted as the ascii character 1.Try using
\\1orr"\n\1;".