V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
lapertem4
V2EX  ›  问与答

求个多字符匹配(英文)

  •  
  •   lapertem4 · Feb 9, 2015 · 2667 views
    This topic created in 4101 days ago, the information mentioned may be changed or developed.

    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 replies    2015-02-09 15:38:27 +08:00
    lapertem4
        1
    lapertem4  
    OP
       Feb 9, 2015
    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()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   964 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 18:11 · PVG 02:11 · LAX 11:11 · JFK 14:11
    ♥ Do have faith in what you're doing.