Does Regex match letters, numbers, and some specific characters?

I am trying to map a bit of a Django URL that may contain:

_ , % , & , + , 0-9 , az , az , (space)

How can I do this to be picked up by the Django URL as a parameter?

 (r'^(?P<chararg>\w+)/IT_NEEDS_TO_BE_HERE/(?P<intarg>\d+)', 'dest') 
+6
source share
3 answers

I played a little and got this - [\w\+%_& ]+ .

So (r'^(?P<chararg>\w+)/IT_NEEDS_TO_BE_HERE/(?P<intarg>\d+)', 'dest') will become

 (r'^(?P<chararg>\w+)/(?P<arg>[\w\+%_& ]+)/(?P<intarg>\d+)', 'dest') 

\w matches any characters and numbers. \+ mathces +

EDIT: \ d is not required.

+5
source

I'm not sure about% char, but the regex will be [_%&+0-9a-zA-Z ]+

+10
source

Since \w means [a-zA-Z0-9_] , you can use:

 [%&+ \w]+ 
+3
source

Source: https://habr.com/ru/post/895594/


All Articles