re sub help

Mike Meyer mwm at
Sat Nov 5 08:14:57 CET 2005

s99999999s2003 at writes:

> hi
> i have a string :
> a =
> "this\nis\na\nsentence[startdelim]this\nis\nanother[enddelim]this\nis\n"
> inside the string, there are "\n". I don't want to substitute the '\n'
> in between
> the [startdelim] and [enddelim] to ''. I only want to get rid of the
> '\n' everywhere else.

Well, I'm not an expert on re's - I've only been using them for three
decades - but I'm not sure this can be done with a single re, as the
pattern you're interested in depends on context, and re's don't handle
that well.

On the

Mike Meyer <mwm at>
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

More information about the Python-list mailing list