Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to match letters, numbers and some specific characters?

I'm trying to match a Django URL bit that can contain:

_, %, &, +, 0-9, a-z, A-Z, (space)

How can I do it so it is picked up by Django's URL matcher, in form of a parameter?

(r'^(?P<chararg>\w+)/IT_NEEDS_TO_BE_HERE/(?P<intarg>\d+)', 'dest')
like image 652
Kristina Brooks Avatar asked Aug 22 '11 14:08

Kristina Brooks


2 Answers

I am not so sure about % char, but regex would be [_%&+0-9a-zA-Z ]+

like image 190
YOU Avatar answered Oct 11 '22 13:10

YOU


As \w means [a-zA-Z0-9_], you could use :

[%&+ \w]+
like image 33
Toto Avatar answered Oct 11 '22 12:10

Toto