Python parse large db over 4gb
Question: I'm trying to parse a `db` file with python that is over 4 gb.

Example from the db file:

    
    
    % Tags relating to '217.89.104.48 - 217.89.104.63'
    % RIPE-USER-RESOURCE
    
    inetnum:        194.243.227.240 - 194.243.227.255
    netname:        PRINCESINDUSTRIEALIMENTARI
    remarks:        INFRA-AW
    descr:          PRINCES INDUSTRIE ALIMENTARI
    descr:          Provider Local Registry
    descr:          BB IBS
    country:        IT
    admin-c:        DUMY-RIPE
    tech-c:         DUMY-RIPE
    status:         ASSIGNED PA
    notify:         order.manager2@telecomitalia.it
    mnt-by:         INTERB-MNT
    changed:        unread@ripe.net 20000101
    source:         RIPE
    remarks:        ****************************
    remarks:        * THIS OBJECT IS MODIFIED
    remarks:        * Please note that all data that is generally regarded as personal
    remarks:        * data has been removed from this object.
    remarks:        * To view the original object, please query the RIPE Database at:
    remarks:        * http://www.ripe.net/whois
    remarks:        ****************************
    
    % Tags relating to '194.243.227.240 - 194.243.227.255'
    % RIPE-USER-RESOURCE
    
    inetnum:        194.16.216.176 - 194.16.216.183
    netname:        SE-CARLSTEINS
    descr:          CARLSTEINS TRAFIK AB
    org:            ORG-CTA17-RIPE
    country:        SE
    admin-c:        DUMY-RIPE
    tech-c:         DUMY-RIPE
    status:         ASSIGNED PA
    notify:         mntripe@telia.net
    mnt-by:         TELIANET-LIR
    changed:        unread@ripe.net 20000101
    source:         RIPE
    remarks:        ****************************
    remarks:        * THIS OBJECT IS MODIFIED
    remarks:        * Please note that all data that is generally regarded as personal
    remarks:        * data has been removed from this object.
    remarks:        * To view the original object, please query the RIPE Database at:
    remarks:        * http://www.ripe.net/whois
    remarks:        ****************************
    

I want to parse each block starting with `% Tags relating to`

and out of the block I want to extract the `inetnum` and first `descr`

This is what I got so far: **(Updated)**

    
    
    import re
    
    with open('test.db', "r") as f:
        content = f.read()
    
        r = re.compile(r''       
                'descr:\s+(.*?)\n',        
                re.IGNORECASE)  
        res = r.findall(content)
        print res
    


Answer: If you only want to get **first** descr :

    
    
    r = re.compile(r''
            'descr:\s+(.*?)\n(?:descr:.*\n)*',
            re.IGNORECASE)
    

If you want inetnum and first descr :

    
    
    [ a + b for (a,b) in re.compile(r''
            '(?:descr:\s+(.*?)\n(?:descr:.*\n)*)|(?:inetnum:\s+(.*?)\n)',
            re.IGNORECASE) ]
    

I must admit I make no use of `% Tags relating to`, and that I suppose that
all `descr` are consecutive.

