Vamsee Krishna Gomatam wrote:
> text = re.sub( "([^<]*)", r' href="http://www.google.com/search?q=\1";>\1', text )
But see what happens when text contains spaces, or quotes, or
ampersands, or...
--
http://mail.python.org/mailman/listinfo/python-list
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)),
>
Oliver Andrich wrote:
> re.sub(r"(.*)",r" href=http://www.google.com/search?q=\1>\1", text)
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)),
Vamsee Krishna Gomatam wrote:
> 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
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
Hi,
2005/5/28, Vamsee Krishna Gomatam <[EMAIL PROTECTED]>:
> 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 que