Splitting a string

Christoph Zwerschke cito at online.de
Tue Feb 14 06:42:13 EST 2006


Nico Grubert wrote:

> I'd like to split a string where 'and', 'or', 'and not' occurs.
> Example string:
> s = 'Smith, R. OR White OR Blue, T. AND Black AND Red AND NOT Green'

Here is a solution without using the re module:
s.replace(' AND NOT ', ' OR ').replace(' AND ', ' OR ').split(' OR ')

-- Christoph



More information about the Python-list mailing list