Matching a string up to a word

Peter Hansen peter at
Wed Sep 4 08:42:47 EDT 2002

Dag wrote:
> I have a string that contains an ID number a file path and a date, kind
> of like this:
> 23545 /this/is a/path/to/a file Sun Sep 7 2002.
> I want to extract the file name.  If I could be sure that the file path
> had no spaces or if it would be quited it would be easy.  Unfortunatly 
> many files will have spaces and changing the format of the output I'm
> dealing with isn't possible.  I do however know that the file name starts 
> after the first whitspace and that it's always followed by a three letter 
> day name (like Mon, Tue etc.)  Given this is there an easy way to extract 
> the whole file path from the string.

Not unless you can restrict the possibilities still further.  What
if the file name ended with a space and a three-letter name?

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.


More information about the Python-list mailing list