a regular expression problem

Leefurong leefurong at gmail.com
Fri Oct 10 11:04:42 EDT 2008


> > I want to use django to dispatch url.
> > The url is like /test/Google/6,and my patten is r'^/test/(?P<q>\b\W+
\W should be \w, a typo? :)
> > \b)/(?P<h>\d+)$'.
> > It works when the string is English(like Google), but fails when the
> > string is in foreign language.
Try this:
r'(?u)^/test/(?P<q>\b\w+\b)/(?P<h>\d+)$'
if ?u doesn't work, try ?L.
I'm not sure which encoding a url uses.(locale or unicode? I guess
unicode)
>
> Care to give an exemple of url that fails ?
>
> Anyway, if you want to match just *anything* in that path segment, you
> can try:
>
> r'^/test/(?P<q>.+?)/(?P<h>\d+)$'.
I don't think he wants to match anything :)




More information about the Python-list mailing list