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
leetao102
V2EX  ›  Python

请问一下,名字 地址 电话 正则如何正则匹配

  •  
  •   leetao102 · 2015-07-16 02:28:48 +08:00 · 2697 次点击
    这是一个创建于 3200 天前的主题,其中的信息可能已经有所发展或是发生改变。

    var shopInfo = "{\"name\":\"承宣\",\"address\":\"校园路香江公寓1号稀土开发区\",\"position\":\"109.855573,40.627727\",\"entId\":1200,\"isFav\":0,\"tel\":\"13500104392\"}";

    6 条回复    2015-07-16 12:35:01 +08:00
    wkdhf233
        1
    wkdhf233  
       2015-07-16 02:46:37 +08:00
    你这不是JSON吗,干嘛要用正则去匹配。。
    Septembers
        2
    Septembers  
       2015-07-16 02:52:01 +08:00   ❤️ 1
    >>> import re, json
    >>> shopInfo = 'var shopInfo = "{\"name\":\"承宣\",\"address\":\"校园路香江公寓1号稀土开发区\",\"position\":\"109.855573,40.627727\",\"entId\":1200,\"isFav\":0,\"tel\":\"13500104392\"}";'
    >>> re.search('"(.*)";$', shopInfo).group(1)
    '{"name":"承宣","address":"校园路香江公寓1号稀土开发区","position":"109.855573,40.627727","entId":1200,"isFav":0,"tel":"13500104392"}'
    >>> json.loads(_)
    {'entId': 1200, 'address': '校园路香江公寓1号稀土开发区', 'position': '109.855573,40.627727', 'isFav': 0, 'tel': '13500104392', 'name': '承宣'}
    >>>
    Twinkle
        3
    Twinkle  
       2015-07-16 02:58:05 +08:00
    JSON.parse(shopInfo)
    leetao102
        4
    leetao102  
    OP
       2015-07-16 03:26:43 +08:00
    @wkdhf233 抓取一个网页,然后返回这个。。
    leetao102
        5
    leetao102  
    OP
       2015-07-16 03:30:08 +08:00
    khan
        6
    khan  
       2015-07-16 12:35:01 +08:00
    这不是妥妥的 json 么
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5188 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 08:09 · PVG 16:09 · LAX 01:09 · JFK 04:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.