Regular expression, "except end of string", question.

Doug Holton insert at
Thu Jun 17 04:17:11 CEST 2004

Derek Basch wrote:
>which I need to alter to this format:

You need the (?!...) operator:

import re
#replace "/" with "-" if not followed by a word at the end of the string
print re.sub(r"/(?!\w+$)",r"-",s)

but like they said, join and split are better here instead of
using regular expressions.

More information about the Python-list mailing list