[EMAIL PROTECTED] wrote:
> Hey there,
> i have a text file with a bunch of values scattered throughout it.
> i am needing to pull out a value that is in parenthesis right after a
> certain word,
> like the first time the word 'foo' is found, retrieve the values in the
> next set of parenthesis (bar) and it would return 'bar'
> 
> i think i can use re to do this, but is there some easier way?

It's pretty easy with an re:

 >>> import re
 >>> fooRe = re.compile(r'foo.*?\((.*?)\)')
 >>> fooRe.search('foo(bar)').group(1)
'bar'
 >>> fooRe.search('This is a foo bar baz blah blah (bar)').group(1)
'bar'

Kent
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to