difficult regular expression

Matthew Wood woodm at colorado.edu
Tue Oct 29 17:44:07 EST 2002


Imagine that you have the following text:

"""
Here is a list of foods and consumers: Dogs eat <chicken>, <rice>,
<steak>, and other foods. Cats eat <mice>, <rats>, <rabbits>, <marmots>,
and other foods. Chickens eat <grain>, <corn>, <wheat>, and other
foods.  Wow, that's a lot of eating!
"""


There are an undetermined (1 or more) number of "consumers" who each eat
an undetermined (1 or more) number of "foods"

This text is NOT seperated by newlines or anything of the sort.  It is
effectively 1 long line.

I need to create a regular expression that will grab "the things that
Cats eat".

It's easy to grab the section containing the text "Cats ... foods." (not
including the Chickens section.)  However, I need to get just the items:
mice, rats, rabbits, marmots.

I realize that this can be done in 2 steps using a subsequent split or
even another regular expression, but this is just a simple example and I
would love to know how to do it in just one step.

Anyone out there able to help?  I really appreciate it.


And by the way, is there a comp.standard.reg-ex or anything like that? 
This question isn't python centric, but you guys are always so helpful.






-- 
                                                       _________________
------------------------------------------------------/                 
                                                     /   Matthew D. Wood
You do not examine legislation in the light of the  /       Applied Math
benefits it will convey if properly administered,  /  woodm at colorado.edu
but in the light of the wrongs it would do and    /                     
the harms it would cause if improperly           /                      
administered.                                   /                       
-- Lyndon Johnson                              /                        
______________________________________________/-------------------------





More information about the Python-list mailing list