Problem with re module

John Bokma john at castleamber.com
Tue Mar 22 14:16:08 EDT 2011


John Harrington <beartiger.all at gmail.com> writes:

> 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 ([^$])?

[^$] matches: not a $ character

You might want [^\n]

-- 
John Bokma                                                               j3b

Blog: http://johnbokma.com/    Facebook: http://www.facebook.com/j.j.j.bokma
    Freelance Perl & Python Development: http://castleamber.com/



More information about the Python-list mailing list