search/replace in Python (solved)
Vamsee Krishna Gomatam
vamsee_k at nospam.students.iiit.ac.in
Sat May 28 07:22:17 EDT 2005
More information about the Python-list mailing list
Sat May 28 07:22:17 EDT 2005
- Previous message (by thread): search/replace in Python (solved)
- Next message (by thread): smart logging and the "inspect" module ...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 '<a href="%s">%s</a>' % (cgi.escape(urllib.quote(text)), > cgi.escape(text)) > > re.sub(r"<google>(.*)</google>", google_link, "<google>foo bar</google>) Thanks a lot for your reply. I was able to solve it this way: text = re.sub( "<google>([^<]*)</google>", r'<a href="http://www.google.com/search?q=\1">\1</a>', text ) GVK
- Previous message (by thread): search/replace in Python (solved)
- Next message (by thread): smart logging and the "inspect" module ...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list