search/replace in Python

2005-05-28 Thread Vamsee Krishna Gomatam
Hello,
I'm having some problems understanding Regexps in Python. I want
to replace "PHRASE" with
"http://www.google.com/search?q=PHRASE>PHRASE" in a block of 
text. How can I achieve this in Python? Sorry for the naive question but 
the documentation is really bad :-(

Regards,
GVK
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: search/replace in Python (solved)

2005-05-28 Thread Vamsee Krishna Gomatam
Leif K-Brooks wrote:
> Oliver Andrich wrote:
> 
>
> For real-world use you'll want to URL encode and entityify the text:
> 
> import cgi
> import urllib
> 
> def google_link(text):
> text = text.group(1)
> return '%s' % (cgi.escape(urllib.quote(text)),
> cgi.escape(text))
> 
> re.sub(r"(.*)", google_link, "foo bar)


Thanks a  lot for your reply. I was able to solve it this way:
text = re.sub( "([^<]*)", r'http://www.google.com/search?q=\1";>\1', text )


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