爱嘉牛LA

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

1.查找两个字符串中间的字符串

(?<=site=)(.*?)(?=&|$)表示位于‘site’与(‘&’或到结尾)之间的字符串
import re

if __name__ == '__main__':
    line4='?uid=44236341&t=1465730505&parsemessage=2&source=1&token=ca4c0659eafee34b448e9d9022f94a75&authorid=43051171&device_id=8f65d346c2f23ffad1a8a1801ad91e430b&rel=1&tid=39779043&mode=2&version=5.0.0&siteflag=tlq'

    rn=None
    matchTid = re.search(r'(?<=site=)(.*?)(?=&|$)', line4, re.M | re.I)
    if matchTid:
        recommName=matchTid.group()
        if recommName:
            rn=recommName
    else:
        print line4
        mt = re.search(r'(?<=siteflag=)(.*?)(?=&|$)', line4, re.M | re.I)
        if mt:
            rnn=mt.group()
            if rnn:
                rn=rnn
    print rn

 

posted on 2016-06-12 21:00  爱嘉牛LA  阅读(173)  评论(0编辑  收藏  举报