python - 正则表达式求教

查看:176
本文介绍了python - 正则表达式求教的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

{"author":{"user_id":640703312,"user_name":"FOREVERR\u5b89\u5b89","props":null},"content":{"post_id":32334914000,"is_anonym":false,"forum_id":874949,"thread_id":2108034524,"content":"287226800@qq.com    \u8c22\u8c22~<img class=\"BDE_Smiley\" src=\"http:\/\/static.tieba.baidu.com\/tb\/editor\/images\/jd\/j_0043.gif\" width=\"25\" height=\"25\">","post_no":118,"type":"0","comment_num":0,"props":null,"post_index":23,"pb_tpoint":null}}

<type 'str'>


求教如何用正则获取FOREVERR\u5b89\u5b89

解决方案

基于正则的话 "user_name":"(.[^"]*)" 这样就能提取。
这个字符串是json串,所以用json来解析应该更好

import json
jsonobj = json.loads(jsonstr)
username = jsonobj['author']['user_name'] # 获取user_name内容

这篇关于python - 正则表达式求教的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆