V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
lapertem4
V2EX  ›  问与答

求个多字符匹配(英文)

  •  
  •   lapertem4 · 2015-02-09 14:36:09 +08:00 · 1937 次点击
    这是一个创建于 3366 天前的主题,其中的信息可能已经有所发展或是发生改变。

    GET /ecx/ HTTP/1.1
    Host: test.baidu.com
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
    Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
    Accept-Encoding: gzip, deflate
    Cookie: __utma=89925662.1398539168.1423185721.1423185721.1423185721.1; __utmz=89925662.1423185721.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
    Connection: keep-alive

    求个正则匹配 GET或者POST后面的地址(例如/ecx/)和Host后面的地址(例如test.baidu.com)

    1 条回复    2015-02-09 15:38:27 +08:00
    lapertem4
        1
    lapertem4  
    OP
       2015-02-09 15:38:27 +08:00
    s = re.findall(r'^(POST|GET)(.*)HTTP',cont,re.M)
    q = re.findall(r'^Host:(.*)',cont,re.M)

    if s and q:
    print s[0][1].strip()
    print q[0].strip()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5418 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 08:08 · PVG 16:08 · LAX 01:08 · JFK 04:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.