From: <eng...@ss...> - 2003-03-17 14:37:18
|
On Mon, 17 Mar 2003, David Abrahams wrote: > eng...@ss... writes: > > > you were a little greedy, this one:: > > > > text = re.sub(r'[^{][\\]', r'{\textbackslash}', text) > > > > will replace any the backslash AND the preceeding character (except for a > > brace). > > Oops. > > > AND there need to be two backslashes. > > I'm pretty sure that's wrong: note that they're raw strings. Did you > test the result? yes, i used your snippet BUT, there was no literal backslash i just recognized that it said " extbackslash" where it shouldnt. for (my) peaceful sleep i added two lines:: :: using namespace mpl::placeholders; mpl::a_line_with\tbackslash mpl::a_line_without backslash which results in :: namespace. In this book we will usually assume that you have written \begin{ttfamily}\begin{flushleft} \mbox{using~namespace~mpl::placeholders;}\\ \mbox{mpl::a{\_}line{\_}with{\textbackslash}tbackslash}\\ \mbox{mpl::a{\_}line{\_}without~backslash} \end{flushleft}\end{ttfamily} which looks reasonable to me. being an ignorant i did not know what this r's meant. after some trying:: # assume a c-code line # printf("%d\t%s\n",count,message); line = open("code.c").readline() # >>> line # 'printf("%d\\t%s\\n",count,message);' now to replace all backslashes with TB either or:: re.sub('\\\\','TB',line) re.sub(r'\\','TB',line) means we have two backslashes in line (\\t) and te regexp for this is two backslashes '\\' is only one r'\\' gives two. and for getting '{\textbackslash}':: re.sub(r'\\','\\textbackslash',line) BUT then we have the string :: 'printf("%d\textbackslasht%s\textbackslashn",count,message);' which does not have a backslash but an escaped letter t, and prints as :: printf("%d extbackslasht%s extbackslashn",count,message); the problem is one cannot enter a single backslash even in a rawstring, r'\' does not work. cheers -- BINGO: assertively disseminate unique opportunities --- Engelbert Gruber -------+ SSG Fintl,Gruber,Lassnig / A6410 Telfs Untermarkt 9 / Tel. ++43-5262-64727 ----+ |