Regular expression, "except end of string", question.
David Fisher
fishboy at SPAMredSPAMpeanutSPAM.com
Wed Jun 16 21:53:15 EDT 2004
Peter Hansen <peter at engcorp.com> writes:
> 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
$ python
Python 2.3.4 (#1, Jun 13 2004, 11:21:03)
[GCC 3.3.1 (cygming special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> string = "WHITE/CLARET/PINK/XL"
>>> string.replace('/','-',2)
'WHITE-CLARET-PINK/XL'
>>>
><{{{*>
More information about the Python-list
mailing list