views:

167

answers:

3

I want to make a wiki, and i must assign for each url a view. Each url can contain letters (A-Z, a-z), digits and punctuation ('.', ',', '/', '-', '_'). How can i make the expression ?

I want something like this :

(r'^(?P<wiki_page>\w+)/$', 'www.wiki.views.page')

but this works only for letters, digits and '_'.

+1  A: 

You could replace \w in the regex with a regex to match what you're looking for. Perhaps

(r'^(?P<wiki_page>[A-Za-z_/,\.-]+)$, 'www.wiki.views.page')

or similar.

Corey Porter
You forgot to include digits (`0-9`)
harto
+4  A: 

Try this regexp:

r'^(?P<wiki_page>[\w.,/_\-]+)/$'
harto
A: 

I think it's more of a regex question

r'^(?P<wiki_page>[\w\.,_/\-]+)/$'

you can build character classes on top of existing ones

I think you have to escape the dash, or put it last, because dash defines range of characters and you may get a very unexpected side-effect of dash.

Evgeny