推荐学习书目
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 · Dec 18, 2018 · 3291 views
    This topic created in 2709 days ago, the information mentioned may be changed or developed.
    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 replies    2018-12-19 14:33:41 +08:00
    15874103329
        1
    15874103329  
    OP
       Dec 18, 2018
    gallery: JSON.parse(),这些内容是不要的,只要括号里面的内容,搞了好久搞不出来,求大佬帮忙
    JungleHi
        2
    JungleHi  
       Dec 18, 2018
    一遇到要正则我就吓得用前后截取 哈哈哈
    preg_match_all('/"{[\s\S]*}"/', $input_lines, $output_array);
    JungleHi
        3
    JungleHi  
       Dec 18, 2018
    一个正则在线工具
    https://www.phpliveregex.com/#tab-preg-match-all

    "{[\s\S]*}"
    xkv2
        4
    xkv2  
       Dec 18, 2018
    (?<=JSON.parse)\(.*?\)
    V2tizen
        5
    V2tizen  
       Dec 18, 2018   ❤️ 1
    JSON.parse\("([\s\S]*?)"\) 这样也可以
    mingyun
        6
    mingyun  
       Dec 18, 2018
    @JungleHi 这网站太慢了 打不开
    15874103329
        7
    15874103329  
    OP
       Dec 19, 2018
    @V2tizen 老哥,可以了,感谢感谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5227 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 07:41 · PVG 15:41 · LAX 00:41 · JFK 03:41
    ♥ Do have faith in what you're doing.