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

Derek Basch dbasch at
Thu Jun 17 01:17:23 CEST 2004


I have a string like:


which I need to alter to this format:


I developed the below functions to do so. However, something is wrong 
with my regular expression. It currently matches with the following:


I thought perhaps I could exclude the match that includes the end of the 
string with someting like this:


but that didnt work either. Can anyone tell me how to exclude the last 
match? The one with the end of the string "/XL".

Thanks a million,
Derek Basch

import re


def replace_fs(thematch):
    thematch =
    thematch = "-" + thematch[1:]
    return thematch

bs_regex = re.compile(r"([/]\w+)").sub(replace_fs, str(string))
print bs_regex

More information about the Python-list mailing list