Splitting a string

Dylan Moreland dylan.moreland at gmail.com
Tue Feb 14 03:20:26 EST 2006


Woops! Thanks for the correction. I was assuming greediness for some
reason.

Fredrik Lundh wrote:
> Dylan Moreland wrote:
>
> > So I would try something like:
> >
> > pat = re.compile(r" (?:AND|OR|AND NOT) ")
> > pat.split(string)
>
> footnote: this yields:
>
>     ['Smith, R.', 'White', 'Blue, T.', 'Black', 'Red', 'NOT Green']
>
> (the | operator picks the first (leftmost) alternative that results in an
> overall match.)
> 
> </F>




More information about the Python-list mailing list