I'm trying to rewrite the code I saw in this answer:
import re
pat1 = re.compile(r"(^|[\n ])(([\w]+?://[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)", re.IGNORECASE | re.DOTALL)
pat2 = re.compile(r"#(^|[\n ])(((www|ftp)\.[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)", re.IGNORECASE | re.DOTALL)
urlstr = 'http://www.example.com/foo/bar.html'
urlstr = pat1.sub(r'\1<a href="\2" target="_blank">\3</a>', urlstr)
urlstr = pat2.sub(r'\1<a href="http:/\2" target="_blank">\3</a>', urlstr)
print urlstr
Specifically, I tried this:
pattern = re.compile('<a href="javascript:rt\(([0-9]+)\)">Download</a>');
rawtable = pattern.sub(r'\1', rawtable)
where I want to replace something like this:
<a href="javascript:rt(2061)">Download</a>
with this:
2061
I'd like to do the same with this:
<a href="#" onclick="javascript:ra('Name of object one')"
title="Some title Text">Name of Object two</a>
with just
Name of Object two
by doing
pattern = re.compile('<a href="#" onclick="javascript:ra\('(:?[a-zA-Z0-9 +)'\)" title="Some title Text">([a-zA-Z0-9 ]+)</a>');
rawtable = pattern.sub(r'\1', rawtable)
but it doesn't work either. Any tips?