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

Peter Otten __peter__ at web.de
Thu Jun 17 04:07:45 EDT 2004


Peter Hansen wrote:

> 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. :-(

Strictly speaking the problem is underspecified, and your original solution
might still be the best if claret is out tomorrow.

Peter




More information about the Python-list mailing list