本帖最后由 随遇而安8 于 2021-12-5 16:14 编辑
代码如下,正则如果只匹配user_id":(.*?),"fullname":"(.*?)"是可以匹配出所有,但是再往后加上start_time": (.*?),匹配就为空
问题:是不是因为中间隔着“计算机课”这几个汉字,所以才不能匹配出start_time的吗?
[Python] 纯文本查看 复制代码 import re
response = '{"teacher_id":5114,"attendance_id":7727052,"user_id":16786743,"fullname":"张三","lesson_name":"计算机课","lesson_start_time":1633860985,"lesson_end_time":1633862410,"conversion_status":1},{"teacher_id":5114,"attendance_id":8062199,"user_id":12956827,"fullname":"李四","lesson_name":"计算机课","lesson_start_time":1638620201,"lesson_end_time":1638622728,"conversion_status":1},{"teacher_id":5114,"attendance_id":7961271,"user_id":12769816,"fullname":"王五","lesson_name":"计算机课","lesson_start_time":1637061349,"lesson_end_time":1637064881,"conversion_status":1}'
student = re.findall(
'user_id":(.*?),"fullname":"(.*?)".*start_time": (.*?),"lesson_end_time', response)
print(student)
|