V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
15874103329
V2EX  ›  Python

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

  •  
  •   15874103329 · 2018-12-18 16:43:58 +08:00 · 2361 次点击
    这是一个创建于 2151 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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
    7 条回复    2018-12-19 14:33:41 +08:00
    15874103329
        1
    15874103329  
    OP
       2018-12-18 16:48:10 +08:00
    gallery: JSON.parse(),这些内容是不要的,只要括号里面的内容,搞了好久搞不出来,求大佬帮忙
    JungleHi
        2
    JungleHi  
       2018-12-18 17:08:13 +08:00
    一遇到要正则我就吓得用前后截取 哈哈哈
    preg_match_all('/"{[\s\S]*}"/', $input_lines, $output_array);
    JungleHi
        3
    JungleHi  
       2018-12-18 17:10:19 +08:00
    一个正则在线工具
    https://www.phpliveregex.com/#tab-preg-match-all

    "{[\s\S]*}"
    xkv2
        4
    xkv2  
       2018-12-18 17:39:00 +08:00
    (?<=JSON.parse)\(.*?\)
    V2tizen
        5
    V2tizen  
       2018-12-18 17:40:10 +08:00   ❤️ 1
    JSON.parse\("([\s\S]*?)"\) 这样也可以
    mingyun
        6
    mingyun  
       2018-12-18 22:54:54 +08:00
    @JungleHi 这网站太慢了 打不开
    15874103329
        7
    15874103329  
    OP
       2018-12-19 14:33:41 +08:00
    @V2tizen 老哥,可以了,感谢感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5355 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 07:04 · PVG 15:04 · LAX 23:04 · JFK 02:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.