Fredrik Lundh wrote: >>>> re.split("(?i)\s*(?:and not|and|or)\s*", s) > ['Smith, R.', 'White', 'Blue, T.', 'Black', 'Red', 'Green'] This fails for people with nasty names:
>>> s = "James White or Andy Grove and Jack Orr and not James Grand" >>> re.split("(?i)\s*(?:and not|and|or)\s*", s) ['James White', '', 'y Grove', 'Jack', 'r', 'James Gr', ''] Here is an alternative: >>> [s.strip() for s in re.split(r"(?i)\b(?:and|or|not)\b", s) if s.strip()] ['James White', 'Andy Grove', 'Jack Orr', 'James Grand'] Peter -- http://mail.python.org/mailman/listinfo/python-list