Re: Use variable in regular expression

vbr at email.cz vbr at email.cz
Thu Aug 2 13:34:08 CEST 2007


...
> Yesterday's date is 20070731, and assigned to the variable
> "yesterday_date". I want to loop thru a directory and find all of the
> yesterday's data ONLY IF the feature class has the date at the
> BEGINNING of the filename.
...
> I can't figure out the
> syntax of inserting the "^" into the regex. 
> 
...
e.g.

yesterdayRE = re.compile("^"+yesterday_date)
...
should work (assuming yesterday_date is a string), but for that simple tests you may also try e.g.

filename.startswith(yesterday_date)

(with both filename and yesterday_date being strings).

Greetings,
   Vlasta




More information about the Python-list mailing list