[新人求助] 如何用正则提取出 gallery: JSON.parse 中的内容,不要头部的(和尾部的), 就是把 json.loads 拿出来

2018-12-18 16:43:58 +08:00
 15874103329
BASE_DATA.galleryInfo = {
title: '图虫街拍摄影:街拍',
isOriginal: false,
mediaInfo: BASE_DATA.mediaInfo,
gallery: JSON.parse("{\"count\":5,\"sub_images\":[{\"url\":\"http:\\/\\/p3.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261904_tt\",\"width\":797,\"url_list\":[{\"url\":\"http:\\/\\/p3.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261904_tt\"},{\"url\":\"http:\\/\\/pb9.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261904_tt\"},{\"url\":\"http:\\/\\/pb1.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261904_tt\"}],\"uri\":\"origin\\/tuchong.fullscreen\\/22261904_tt\",\"height\":1200},{\"url\":\"http:\\/\\/p99.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261905_tt\",\"width\":1200,\"url_list\":[{\"url\":\"http:\\/\\/p99.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261905_tt\"},{\"url\":\"http:\\/\\/pb3.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261905_tt\"},{\"url\":\"http:\\/\\/pb1.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261905_tt\"}],\"uri\":\"origin\\/tuchong.fullscreen\\/22261905_tt\",\"height\":797},{\"url\":\"http:\\/\\/p99.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261906_tt\",\"width\":1200,\"url_list\":[{\"url\":\"http:\\/\\/p99.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261906_tt\"},{\"url\":\"http:\\/\\/pb3.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261906_tt\"},{\"url\":\"http:\\/\\/pb1.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261906_tt\"}],\"uri\":\"origin\\/tuchong.fullscreen\\/22261906_tt\",\"height\":797},{\"url\":\"http:\\/\\/p99.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261914_tt\",\"width\":1200,\"url_list\":[{\"url\":\"http:\\/\\/p99.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261914_tt\"},{\"url\":\"http:\\/\\/pb3.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261914_tt\"},{\"url\":\"http:\\/\\/pb1.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261914_tt\"}],\"uri\":\"origin\\/tuchong.fullscreen\\/22261914_tt\",\"height\":797},{\"url\":\"http:\\/\\/p99.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261925_tt\",\"width\":1200,\"url_list\":[{\"url\":\"http:\\/\\/p99.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261925_tt\"},{\"url\":\"http:\\/\\/pb3.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261925_tt\"},{\"url\":\"http:\\/\\/pb1.pstatp.com\\/origin\\/tuchong.fullscreen\\/22261925_tt\"}],\"uri\":\"origin\\/tuchong.fullscreen\\/22261925_tt\",\"height\":797}],\"max_img_width\":1200,\"labels\":[\"\\u6444\\u5f71\"],\"sub_abstracts\":[\" \\u6444\\u5f71\\uff1a\\u6df1\\u84dd1970\",\" \",\" \",\" \",\" \"],\"sub_titles\":[\"\\u56fe\\u866b\\u8857\\u62cd\\u6444\\u5f71\\uff1a\\u8857\\u62cd\",\"\\u56fe\\u866b\\u8857\\u62cd\\u6444\\u5f71\\uff1a\\u8857\\u62cd\",\"\\u56fe\\u866b\\u8857\\u62cd\\u6444\\u5f71\\uff1a\\u8857\\u62cd\",\"\\u56fe\\u866b\\u8857\\u62cd\\u6444\\u5f71\\uff1a\\u8857\\u62cd\",\"\\u56fe\\u866b\\u8857\\u62cd\\u6444\\u5f71\\uff1a\\u8857\\u62cd\"]}"),
siblingList: [],
publish_time: '2018-03-10 09:08:40',
group_id: '6531116766146331139',
item_id: '6531116766146331139',
share_url: 'https://m.toutiao.com/group/6531116766146331139/',
abstract: ''.replace(/<br \/>/ig, ''),
repin: 0
2368 次点击
所在节点    Python
7 条回复
15874103329
2018-12-18 16:48:10 +08:00
gallery: JSON.parse(),这些内容是不要的,只要括号里面的内容,搞了好久搞不出来,求大佬帮忙
JungleHi
2018-12-18 17:08:13 +08:00
一遇到要正则我就吓得用前后截取 哈哈哈
preg_match_all('/"{[\s\S]*}"/', $input_lines, $output_array);
JungleHi
2018-12-18 17:10:19 +08:00
一个正则在线工具
https://www.phpliveregex.com/#tab-preg-match-all

"{[\s\S]*}"
xkv2
2018-12-18 17:39:00 +08:00
(?<=JSON.parse)\(.*?\)
V2tizen
2018-12-18 17:40:10 +08:00
JSON.parse\("([\s\S]*?)"\) 这样也可以
mingyun
2018-12-18 22:54:54 +08:00
@JungleHi 这网站太慢了 打不开
15874103329
2018-12-19 14:33:41 +08:00
@V2tizen 老哥,可以了,感谢感谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/518676

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX