Python - regex to match url with mongo object id -
i trying write regex matches url of following format:
/api/v1/users/<mongo_object_id>/submissions
where example of mongo_object_id 556b352f87d4693546d31185
. have cooked following pattern, not seems work.
/api/v1/users\\/(?=[a-f\\d]{24}$)(\\d+[a-f]|[a-f]+\\d)\\/submissions
any appreciated.
this (considering 24 hex chars), using raw keyword before string no need escape double slashes:
r'\/api\/v1\/users\/([a-f\d]{24})\/submissions'
python console:
>>> re.findall(r'\/api\/v1\/users\/([a-f\d]{24})\/submissions','/api/v1/users/556b352f87d4693546d31185/submissions') ['556b352f87d4693546d31185']
Comments
Post a Comment