python - 忽略 re 上的引号
问题描述
我试图将我的数据转换为字典列表,例如
example_dict = {"host":"146.204.224.152",
"user_name":"feest6811",
"time":"21/Jun/2019:15:45:24 -0700",
"request":"POST /incentivize HTTP/1.1"} #note: not everything is a POST
我的数据:
146.204.224.152 - feest6811 [21/Jun/2019:15:45:24 -0700] "POST /incentivize HTTP/1.1" 302 4622
197.109.77.178 - kertzmann3129 [21/Jun/2019:15:45:25 -0700] "DELETE /virtual/solutions/target/web+services HTTP/2.0" 203 26554
156.127.178.177 - okuneva5222 [21/Jun/2019:15:45:27 -0700] "DELETE /interactive/transparent/niches/revolutionize HTTP/1.1" 416 14701
100.32.205.59 - ortiz8891 [21/Jun/2019:15:45:28 -0700] "PATCH /architectures HTTP/1.0" 204 6048
168.95.156.240 - stark2413 [21/Jun/2019:15:45:31 -0700] "GET /engage HTTP/2.0" 201 9645
71.172.239.195 - dooley1853 [21/Jun/2019:15:45:32 -0700] "PUT /cutting-edge HTTP/2.0" 406 24498
180.95.121.94 - mohr6893 [21/Jun/2019:15:45:34 -0700] "PATCH /extensible/reinvent HTTP/1.1" 201 27330
144.23.247.108 - auer7552 [21/Jun/2019:15:45:35 -0700] "POST /extensible/infrastructures/one-to-one/enterprise HTTP/1.1" 100 22921
我的代码:
pattern = """
(?P<host>.*) #User host
(-\ ) #Separator
(?P<user_name>\w*) #User name
(\ \[) #Separator for pharanteses and space
(?P<time>\S*\ -0700) #time
(\]\ ) #Separator for pharanteses and space
(?P<request>\w* ")
"""
for user in re.finditer(pattern,logdata,re.VERBOSE):
print(user.groupdict())
我无法摆脱引号。试图添加\"或只是"到分隔线,但后来我无法得到任何输出。
解决方案
推荐阅读
- angular - msal.js 访问令牌中的自定义声明
- javascript - 将时区设置为“欧洲/伦敦”时,IE 11 抛出“'timeZone' 超出有效范围”
- python - OSError: [Errno 12] 使用 python 多处理池时无法分配内存
- node.js - 种子 MongoDB 数据
- javascript - 在节点 js 上读取 .psv 文件内容花费的时间太长(超过 200 万行数据)
- javascript - 为什么 draft-js / react-rte 不会在文本编辑器中加载 iframe?
- sql-server - 在 SQL 中将一个长字符串拆分为一组较短的字符串
- netlogo - 如何更新用于在循环中选择海龟的比例?
- angular - Angular - 身份验证标头
- java - static 关键字在这里做什么?