[Tutor] replacing spaces and tabs before the code
=?gb2312?B?zPrKrw==?=
winglion1 at 163.com
Sun Nov 6 11:21:55 CET 2005
I am try to write a code that turn codes to html file
I do it like this,(It is take out from example code form sourceforge):
re_lead=re.compile(r"[\f\t]")
re_space=re.compile(r"[ ]{2,}")
src = re_lead.sub(r"     ",src)
src = re_lead.sub(r"     ",src)
src is the code string!
as you can see, I repeat the search many time to replace two or more \t before the code line.
but, if somebody use space, some time may be up to 8 or 9 times before a line,it
would be stupid to repeat 8 time of search to replace them!
It's there a method that can replace all spaces with " " just at one search
action, and pass the single space between words!
I am new to re module,please help! thanks!
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡winglion1 at 163.com
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2005-11-06
More information about the Tutor
mailing list