My Django URLs not picking up dashes

Cato Johnston picture Cato Johnston · Feb 10, 2009 · Viewed 8.1k times · Source

Im trying to work out a url that will match domain.com\about-us\ & domain.com\home\

I have a url regex:

^(?P<page>\w+)/$

but it won't match the url with the - in it.

I've tried

^(?P<page>\.)/$
^(?P<page>\*)/$

but nothing seems to work.

Answer

Alex Goodwin picture Alex Goodwin · Feb 10, 2009

Try: ^(?P<page>[-\w]+)/$

[-\w] will accept a-z 1-9 and dash