re.sub do not replace portion of match

2009-10-03 Thread J Wolfe
Hi, Is there a way to flag re.sub not to replace a portion of the string? I have a very long string that I want to add two new line's to rather than one, but keep the value X: string = "testX.\n.today" <-- note X is a value string = re.sub("testX.\n.","testX.\n\n.", stri

Re: re.sub do not replace portion of match

2009-10-03 Thread Duncan Booth
J Wolfe wrote: > Hi, > > Is there a way to flag re.sub not to replace a portion of the string? > > I have a very long string that I want to add two new line's to rather > than one, but keep the value X: > > string = "testX.\n.today" <-- note X is a value > string = re.sub("test...

Re: re.sub do not replace portion of match

2009-10-02 Thread J Wolfe
Thanks Duncan, I did look at that, but it was kinda greek to me. Thanks for pulling out the part I was looking for that should do the trick. Jonathan > http://www.python.org/doc/current/library/re.html#re.sub > > > Backreferences, such as \6, are replaced with the substring matched by > > group