Matching a string up to a word

Peter Hansen peter at
Wed Sep 4 22:31:46 EDT 2002

Dag wrote:
> In article <3d75ffaa$1 at>, Peter Hansen wrote:
>>Can you instead guarantee the format of the date that follows the 
>>filename?  Will it always consist of the day of the week, the month,
>>the date, and the year?  That would turn this into a relatively
>>simple problem.
> Yes I can guarentee the last four fields be in that date format.  
> Actually I think that solved it.  I'll split on whitespaces into
> an array, and remove the first and last four fields, and then join
> whatever's left.  That should do it.  I was stuck thinking how to 
> parse it left to right.  

I was thinking of something like that.  This should do it then:

   filename = ' '.join(field.split(' ')[1:-4])

That is, provided you never expect to see more than one consecutive
space in your filenames...


More information about the Python-list mailing list