re.sub do not replace portion of match

J

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 = "test........X.\n.today" <-- note X is a value
string = re.sub("test........X.\n.","test........X.\n\n.", string)

This just replaces X with the replacement string.

Thanks,
Jonathan
 
J

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top