Problem with re module

John Harrington beartiger.all at gmail.com
Tue Mar 22 13:56:21 EDT 2011


I'm trying to use the following substitution,

     lineList[i]=re.sub(r'(\\begin{document})([^$])',r'\1\n\n
\2',lineList[i])

I intend this to match any string "\begin{document}" that doesn't end
in a line ending.  If there's no line ending, then, I want to place
two carriage returns between the string and the non-line end
character.

However, this places carriage returns even when the string is followed
directly after with a line ending.  Can someone explain to me why this
match is not behaving as I intend it to, especially the ([^$])?

Also, how can I write a regex that matches what I wish to match, as
described above?

Many thanks,
John



More information about the Python-list mailing list