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

Peter Hansen peter at engcorp.com
Wed Jun 16 20:01:21 EDT 2004


David Eppstein wrote:

> Do you really need regexps for this?
> 
>>>>string = "WHITE/CLARET/PINK/XL"
>>>>'-'.join(string.split('/',2))
> 
> 'WHITE-CLARET-PINK/XL'

Dang!  I started with split('/', 2) but stared at the
result trying to figure out how the heck to join it
to get the right result and ended up punting. :-(

-Peter



More information about the Python-list mailing list