Saturday, July 28, 2012

Re: Url regex keeps django busy/crashing

On 07/26/12 09:45, Joe wrote:
> url(r'^(?P<item_url>(\w+-?)*)/$', 'detail'),
>
> replaced with:
>
> url(r'^(?P<item_url>[\w-]+)/$', 'detail'),

Russell gave you good background on the why (including that Django
was stung by the same issue). It would help if you more clearly
defined what you wanted to target. Your first one can match things like

x-x-x-x-

with trailing dashes, and your second one can match things like

------ # pure dashes
---xxx # leading dashes
--xx-- # leading and trailing dashes

I suspect you want an expression something like

(?P<item_url>\w+(?:-\w+)*)/$

perhaps having a "?" after the terminal slash to make it optional.
This expression is roughly "one or more \words separated by one
dash." You might change "\w" to "[a-zA-Z]" to ensure you can't
match odd things like

_-_-_-_

("\w" includes underscores).

-tkc



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment