split() with a separator set

Oleg Broytmann phd at phd.russ.ru
Mon Jun 19 11:23:04 EDT 2000


On 19 Jun 2000, Igor V. Rafienko wrote:
> I've just started learning Python, so, please bear with me. 

   Welcome!

> But what if I have several one-character separators? Obviously:
> 
> # input looks like this: 'foo:bar|baz/zot'
> # I want [ 'foo', 'bar', 'baz', 'zot' ]
> string.split( src, ":|/" )


   Regular expressions are your friends!

import re
re.split("[:|/]", src )


   (Russian? Can read/write cyrillic?)

Oleg.            (All opinions are mine and not of my employer)
---- 
    Oleg Broytmann      Foundation for Effective Policies      phd at phd.russ.ru
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list