Harlin Seritt wrote: > I am trying to find some matches and have them put into a list when > processing is done. I'll use a simple example like email addresses. > > My input is the following: > wordList = ['myname1', '[EMAIL PROTECTED]', '[EMAIL PROTECTED]', > '[EMAIL PROTECTED]', '[EMAIL PROTECTED]'] > > My regular expression would be something like '[EMAIL PROTECTED]' (I realize > it could and should be more detailed but that's not the point for now). > > I would like to find out how to output the matches for this expression > of my 'wordList' into a neat list variable. How do I get this done?
that's more of a list manipulation question than a regular expression question, of course. to apply a regular expression to all items in a list, apply it to all items in a list. a list comprehension is the shortest way to do this: >>> out = [word for word in wordList if re.match("[EMAIL PROTECTED]", word)] >>> out ['[EMAIL PROTECTED]', '[EMAIL PROTECTED]', '[EMAIL PROTECTED]'] </F> -- http://mail.python.org/mailman/listinfo/python-list