Replace every n instances of a string

Tom Cross thomasacross at
Fri Aug 15 23:25:57 CEST 2003


I have a function that returns to me a text representation of Unicode
data, which looks like this:


I would like to add carriage returns to this for usability.  But I
don't want to add a return after each "\u" I encounter in the text
(regexp comes to mind if I did).  I want to add a return after each 12
"\\u"s I encounter in the string.

Any ideas?  Do I not want to search for "\\u" but instead just insert
a \n after each 72 characters (equivalent to 12 \uXXXX codes)?  Would
this provide better performance?  If so, what would be the easiest way
to do that?

Thanks much!

More information about the Python-list mailing list