On Wed, Jul 22, 2015 at 11:03 AM, Pablo Lucena <plucen...@gmail.com> wrote: > str.split and re are a nice quick way to do it: > >>>> def get_data(data): > import re > port_re = re.compile(r'(\w+)\((\S+-\S+)\)') > cidr_re = re.compile(r'\[(.*?)\]') > _, proto_port, cidr = data.rsplit(":", 2) > port_match = port_re.search(proto_port) > proto, port = port_match.group(1), port_match.group(2) > port = port.split("-")[0] > cidr_match = cidr_re.search(cidr) > cidr = cidr_match.group(1) > return dict(port=port, proto=proto, cidr=cidr)
The textual output is coming from his quick little Python loop. No need to parse that when you can go to the underlying objects :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list