Python re to extract useful information from each line

Emile van Sebille emile at fenx.com
Wed Apr 29 17:22:40 EDT 2015


On 4/29/2015 1:49 PM, Kashif Rana wrote:
> pol_elements = re.compile('id\s(?P<p_id>.+?)(?:\sname\s(?P<p_name>.+?))?\sfrom\s(?P<p_from>.+?)\sto\s(?P<p_to>.+?)\s{2}(?P<p_src>[^\s]+?)\s(?P<p_dst>[^\s]+?)\s(?P<p_port>[^\s]+?)(?:(?P<p_nat_status>\snat)\s(?P<p_nat_type>[^\s]+?)(?P<p_nat_ip>\sdip-id\s[^\s]+?)?)?\s(?P<p_action>[^\s]+?)(?:\sschedule\s(?P<p_schedule>[^\s]+?))?(?P<p_log_status>\slog)?$'
> )


... and that's why we avoid regular expressions... it makes my head hurt 
just looking at that line noise.

Emile






More information about the Python-list mailing list