views:

46

answers:

1

A project I'm currently working on has a sort of proxy functionality where users can browse to another URL through the site. I was hoping the URL could be something like this:

www.mydomain.com/browser/[URL here]

However I'm having trouble capturing a URL as a parameter like this. I think my inexperience with regex is failing me here :( My URL conf looks like this:

urlpatterns += patterns('',
    url(r'^browser/(?P<url>\w+)/$', browser_proxy, name='browser_proxy'),
)

I'm thinking the \w+ isn't sufficient to capture an arbitrary URL. Anyone know what I should be using here to capture a URL as a parameter like this?

Thanks for any help.

+3  A: 

\w means a "word" character, i.e. alphanumeric and underscore. It is equivalent to the set [a-zA-Z0-9_]. You can match any character with a period. I.e.:

urlpatterns += patterns('',
   url(r'^browser/(?P.+)/$', browser_proxy, name='browser_proxy'),
)
rjmunro
Thanks very much rj, works perfectly! Sorry I didn't thank you sooner, for some reason the comment box wasn't showing for me until now :)
Peter K