我正在尝试编写一个正则表达式来匹配任何包含 /?
的路径,以确定它是否是一个查询字符串。
要匹配的示例字符串是这样的:/mysite/path/to/whatever/?page=1
到目前为止,我认为这会匹配 re.match(r'/\?', '/mysite/path/to/whatever/?page=1')
但是好像不匹配
最佳答案
此代码已为您编写。无需重新发明轮子:
import urlparse
print urlparse.urlparse('/mysite/path/to/whatever/?page=1')
http://docs.python.org/library/urlparse.html#module-urlparse
关于python正则表达式匹配查询字符串路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9850933/