Asma Gheisari
Asma Gheisari

Reputation: 6294

have a url that accepts all characters

I want a url that accepts all characters,for example:

(r'^company/(?P<key>[a-zA-Z]+)/doclist/$','CompanyHub.views.docList')

for key parameter instead of just ascii alphabetic characters It accepts all characters include numbers,symbols like $,-,_,...,alphabet,unicode characters,...

how can I do this?

Upvotes: 19

Views: 25127

Answers (3)

Ralph Bolton
Ralph Bolton

Reputation: 854

As others have said:

(.*)

...will match all characters, but it will also match an empty string (which might be bad if the regex is at the end of a URL). If you want to force that at least one character is required, then use this:

(.+)

Just to be clear, these work in the middle of URLs as well as at the end, so something like this works perfectly fine:

url(ur'^package\/(?P<pkgname>.+)\/(?P<pkgversion>.+)', ... )

(and as @tsikov says, use a preceding 'u' for unicode)

Upvotes: 2

anonymous
anonymous

Reputation: 1532

Your code should look like this:

(ur'^company/(?P<key>.*)/doclist/$','CompanyHub.views.docList')

We need the 'u' at the beginning to tell python that the string accepts unicode characters.

Upvotes: 39

Alex W
Alex W

Reputation: 38253

RegEx would look like this:

(.*)

That should match all characters except new line characters.

Upvotes: 15

Related Questions