Thursday, February 21, 2013

Re: url pattern correct but not working

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAlEmfh8ACgkQuYLL1cDjHx00qQCcDsFb8ZobzoyI8H4FqdzSRKRM
B7sAnRv8C9Dk/KxuoeMWpmK8PpLI+56F
=c/ve
-----END PGP SIGNATURE-----
On Thu, 21 Feb 2013 10:46:05 -0800 (PST) Aswani Kumar
<aswin.1231@gmail.com> wrote:
> my url pattern
>
> [a-zA-Z0-9]-(?P<nid>\d+).html
>
> urls will be like
>
> news-in-finland-yesterday-festival-3456.html
>
> i want 3456 which is news id.
>
> the regex is correct but not working if i keep it in urls.
> url('^[a-zA-Z0-9]-(?P<nid>\d+).html$', 'tempa'),

Whether your pattern is correct or depends on what you want to achieve:
- if you want to match a single digit or letter followed by a dash and
a number uf digits for the id, then your pattern is correct.
- if you want your pattern to macht the url you have given, then its
not correct.

You want something like this (untested):

url(r'^([a-zA-Z0-9\-]+-(?P<nid>\d+).html$', 'tempa')

And that only matches lower- and upper-case letters, numbers and
dashes. If you want to allow any non-ascii characters you might want
something different in that first parantheses.

Have fun,

Arnold

No comments:

Post a Comment