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

David Eppstein eppstein at ics.uci.edu
Wed Jun 16 19:38:45 EDT 2004


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'

-- 
David Eppstein                      http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science



More information about the Python-list mailing list