I'm writing a quick regular expression in python to test an url path. I want it to look for a number of verbs and optionally pull out an integer:
pattern = r"/(?P<verb>view|edit|list|create|delete)(/(?P<id>\d{1,4})/)?"
paths = (
"/view/1/",
"/edit/15/",
"/create/",
"/list/",
"/delete/2/",
"/dummy/" #will not match
)
This pulls out the "verb" as well as an "id". Where there is no id it sets the group result to None. What I want is for the match to fail on paths that dont require an id (list, create) but to succeed on the others (view, edit,delete) and pull out the id.
Any ideas?