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

Derek Basch dbasch at yahoo.com
Wed Jun 16 20:48:00 EDT 2004


In article <eppstein-EA7ACC.16384516062004 at news.service.uci.edu>, 
eppstein at ics.uci.edu says...
> In article <MPG.1b3a76057bb1198d989681 at news-server.san.rr.com>,
>  Derek Basch <dbasch at yahoo.com> wrote:
> 
> > string = "WHITE/CLARET/PINK/XL"
> > 
> > which I need to alter to this format:
> > 
> > string = "WHITE-CLARET-PINK/XL"
> 
> Do you really need regexps for this?
> 
> >>> string = "WHITE/CLARET/PINK/XL"
> >>> '-'.join(string.split('/',2))
> 'WHITE-CLARET-PINK/XL'
> 
> 

Thanks Peter and David,

It always comforting to know that a really simple solution exists after 
you waste a couple of hours messing with Regular Expressions. :)

Cheers,
Derek



More information about the Python-list mailing list