Here's my take on that: loc = re.search('for\s+(\w+)', string).group(1)
Not much different, really, but it does allow for multiple spaces (\s+) as well as requiring at least one character in the word (\w+), and I use a matching group to extract the location directly instead of splitting the string "by hand". :) David On Saturday 15 May 2010 8:38:01 am Xavier Ho wrote: > On Sat, May 15, 2010 at 9:32 PM, timo verbeek <timoverbee...@gmail.com>wrote: > > On May 15, 1:02 pm, timo verbeek <timoverbee...@gmail.com> wrote: > > Place starts always with for > > Okay, much better. > > Given that constraint, it looks like regular expression can do the job. I'm > not very experienced with regex, though. > > \w* matches a whole word composed of letters and numbers by default. > > >>> result = re.search('for \w*', 'Give me the weather for London please.') > >>> result.group() > > 'for London' > > >>> result.group().split()[1] > > 'London' > > Cheers, > Xav
signature.asc
Description: This is a digitally signed message part.
-- http://mail.python.org/mailman/listinfo/python-list