正则表达式匹配多行

a.*?b

匹配

最短的,以a开始,以b结束的字符串

。如果把它应用于

aabab

的话,它会匹配

aab(第一到第三个字符)

ab(第四到第五个字符)

 

#Shell 脚本测试实例

  # re.S means: Make the '.' special charactermatch any character at all,

    # including a newline; without this flag,'.' will match anything except a newline.

    # '(.+?)' means: this is a lazzy match.When the fist 'Response>' is found, then

    # it will not try to match the next'Response>'

   #错误表达式

    #re_patt = re.compile(r'<ResponseStatus="OKAY" CongLvl="LEVEL0"*(.+?)Response>', re.S)

    #re_patt = re.compile(r'<RequestAction="READ" RequestId="100000">\w*\n<ResponseStatus="OKAY"*(.+?)Response>', re.S)

    #re_patt = re.compile(r'<RequestAction="READ" RequestId="100000">.*\n<ResponseStatus="OKAY".*RequestId="100000">', re.S)

    #re_patt = re.compile(r'<RequestAction="READ" RequestId="100000">*(.+?)\n<ResponseStatus="OKAY"*(.+?)RequestId="100000">')

    #re_patt = re.compile(r'<RequestAction="READ"*(.+?)<ResponseStatus="OKAY"*(.+?)RequestId="100000">', re.S)

    #re_patt = re.compile(r'<RequestAction="READ"*(.+?)<Response Status="OKAY"RequestId="100000">', re.S)

    #re_patt = re.compile(r'<ResponseStatus="OKAY" CongLvl="LEVEL0"*(.+?)Response>', re.S)

    #re_patt = re.compile(r'<RequestAction="READ"RequestId="100000">*(.+?)encoding="UTF-8"?>', re.S)

    #re_patt = re.compile(r'<RequestAction="READ" RequestId="100000">\w*', re.S)

    #re_patt = re.compile(r'<RequestAction="READ" RequestId="100000">*(.+?)Response>',re.S)

    #re_patt = re.compile(r'<RequestAction="READ" RequestId="100000".*')

    #re_patt = re.compile(r'<RequestAction="READ" RequestId="100000"*(.+?)Response>', re.S)

    #re_patt = re.compile(r'<RequestAction="LOGIN"RequestId="100000"><Authentication><ClientName>Administrator</ClientName><Password>5420!Gls</Password></Authentication></Request><?xmlversion="1.0" encoding="UTF-8"?>*(.+?)Response>',re.S)

    #re_patt = re.compile(r'<RequestAction="READ" RequestId="100000">.*\n<ResponseStatus="OKAY"*(.+?)Response>', re.S)

   #正确表达式

    re_patt = re.compile(r'<RequestAction="READ" RequestId="100000">.*?<ResponseStatus="OKAY".*?Response>', re.S)


    str1 = ""

    # save the readout lines into str1.

    for line in read_file:

        str1 = str1 + line

 

    print str1

    result = re_patt.search(str1)

    if result != None:

        print 'test2'

        tempResult1 = '<ResponseBatch>' +result.group(0) + '</ResponseBatch>'

        newfile.write(tempResult1)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值