Menu

Get contents between two known lines

2010-10-28
2013-11-27
  • Sean Nguyen

    Sean Nguyen - 2010-10-28

    Hi,

    I am trying to extract the content of my text between 2 known lines.
    Raw Request: {
    line1
    line2
    line3
    }
    Request End

    I want to get these line out:

    line1
    line2
    line3
    }

    Can anybody show me how to do that?

    Thanks,

    Son Nguyen

     
  • DangGriffith

    DangGriffith - 2013-11-27
    from pyparsing import Literal, SkipTo
    rr = Literal("Raw Request: {").suppress() + SkipTo("Request End")
    
    sample = """Raw Request: {
    line1
    line2
    line3
    }
    Request End"""
    
    res = rr.parseString(sample)
    print(res)
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.