Python re to extract useful information from each line

Kashif Rana kashifrana84 at
Wed Apr 29 22:42:08 CEST 2015

Hello Experts

I have below lines with some variations.

1- set policy id 1000 from "Untrust" to "Trust" "Any" "" "HTTP" nat dst ip port 8000 permit log

2- set policy id 5000 from "Trust" to "Untrust" "Any" "" "HTTP" nat src permit schedule "14August2014" log

3- set policy id 7000 from "Trust" to "Untrust" "Users" "Any" "ANY" nat src dip-id 4 permit log

4- set policy id 7000 from "Trust" to "Untrust" "servers" "Any" "ANY" deny

Please help me to write the regular expression to extract below information in parenthesis, if exist from each line. Please note that some items may exist or not like nat or log

set policy id (id) from (from) to (to) (source) (destination) (service) nat (src or dst) (dip-id 4) or (ip port (dst-port) (action) schedule (schedule) (log)

More information about the Python-list mailing list