Python regex with question mark literal

前端 未结 5 1256
耶瑟儿~
耶瑟儿~ 2020-12-06 17:30

I\'m using Django\'s URLconf, the URL I will receive is /?code=authenticationcode
I want to match the URL using r\'^\\?code=(?P.*)$\'

5条回答
  •  粉色の甜心
    2020-12-06 17:58

    supress the regex metacharacters with []

    >>> s
    '/?code=authenticationcode'
    >>> r=re.compile(r'^/[?]code=(.+)')
    >>> m=r.match(s)
    >>> m.groups()
    ('authenticationcode',)
    

提交回复
热议问题