python正则表达式匹配查询字符串路径

标签 python regex

我正在尝试编写一个正则表达式来匹配任何包含 /? 的路径,以确定它是否是一个查询字符串。

要匹配的示例字符串是这样的:/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/

相关文章:

ruby - 将对齐方式放入 <td> 标记的正则表达式

python - python中的正则表达式多次删除字符和数字的孤立出现

python - 我的 python 脚本中的枚举没有按预期工作?

url 的正则表达式过滤器列表

javascript - 正则表达式 : Allow only characters a-z, A-Z

regex - mongoexport 正则表达式未知选项

python - 更改 pandas 绘图后端以获取交互式绘图而不是 matplotlib 静态绘图

python - 从另一个类借用类方法(Python 3)

python elasticsearch格式数据

php - 去除除 src 之外的所有 HTML 属性