Parse Whois data using Regex - Ignore field Repetition
I'm trying to parse Whois data within a file in order to get information
about specific fields. The format looks like this:
route: 123.45.67.8/91
descr: Information
descr: Information 2
origin: AS5462
notify: foo@bar.net
mnt-by: AS5462-MNT
remarks: For abuse notifications please file an online case @
http://www.foo.com/bar
changed: foo@bar.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.foo.net/bar
remarks: ****************************
route: 123.45.67.8/91
descr: FOO-BAR
origin: AS3269
mnt-by: BAR-BAZ
changed: foo@bar.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 would like to retrieve the route, descr and origin field only. The
problem I have is sometimes you have multiple descr fields and I would
like to retrieve only the first occurrence of it in case there are
several.
What is the best way to achieve that using regex in python?
No comments:
Post a Comment