regexp search for variable and string

Joshua Newman lazerpub at yahoo.com
Sat May 18 23:44:32 EDT 2002


Sorry if this has been asked and answered innumerable times.  I
couldn't find the answer anywhere.

I'm trying to grab some news with wget and python.
I can't regexp for a variable (date) and specific words in the same
re.compile expression.  Any hints?

#get today's date
date= time.strftime("%Y/%m/%d", time.localtime(time.time()))

#construct a string to search for today's date and wire services but no
#sports or index pages
restring="""r'("""+date+"""|aponline|reuters)(?!/sports|.*index.html)'"""
today=re.compile(restring)

#above doesn't work, but:
#today=re.compile(r'(2002/05/19|aponline|reuters)(?!/sports|.*index.html)'
#works fine with:
todaysurl=re.findall(today,onlinenewspaperURLs)

Can I do this in one regexp?
Thanks for the help

Joshua



More information about the Python-list mailing list