"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > Hi, I have a list of strings. And I want to find the subset which > matches a particular regular expression. > > import re > ll = ('a', 'b', 's1', 's2', '3s') > p = re.compile('^s.*') > newList = filter(lambda s: p.match(s), ll) > > I suppose there should be simple function to do this in re module. Is > there any? > > I searched google, but could not find one, may be for keywords were not > perfect.
I dont believe there exists such a function. I would have written it using a list comprehension. >>> import re >>> ll = ('a', 'b', 's1', 's2', '3s') >>> p = re.compile('^s.*') >>> newList = [s for s in ll if p.match(s)] >>> newList ['s1', 's2'] -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info -- http://mail.python.org/mailman/listinfo/python-list