regex for url paramter

Andreas Volz usenet-spam-trap at brachttal.net
Tue Dec 7 17:27:16 EST 2004


Hi,

I try to extract a http target from a URL that is given as parameter.
urlparse couldn't really help me. I tried it like this

url="http://www.example.com/example.html?url=http://www.example.org/exa
mple.html"

p = re.compile( '.*url=')
url = p.sub( '', url)
print url
> http://www.example.org/example.html

This works, but if there're more parameters it doesn't work:

url2="http://www.example.com/example.html?url=http://www.example.org/exa
mple.html&param=1"

p = re.compile( '.*url=')
url2 = p.sub( '', url2)
print url2
> http://www.example.org/example.html&param=1

I played with regex to find one that matches also second case with
multible parameters. I think it's easy, but I don't know how to do. Can
you help me?

regards
Andreas



More information about the Python-list mailing list