Re: Python re to extract useful information from each line

2015-08-19 Thread Paul McGuire
Here is a first shot at a pyparsing parser for these lines: from pyparsing import * SET,POLICY,ID,FROM,TO,NAT,SRC,DST,IP,PORT,SCHEDULE,LOG,PERMIT,ALLOW,DENY = map(CaselessKeyword, "SET,POLICY,ID,FROM,TO,NAT,SRC,DST,IP,PORT,SCHEDULE,LOG,PERMIT,ALLOW,DENY".split(',')) integer = Word(nums) ipA

Re: Python re to extract useful information from each line

2015-04-29 Thread sohcahtoa82
On Wednesday, April 29, 2015 at 1:42:18 PM UTC-7, Kashif Rana wrote: > Hello Experts > > I have below lines with some variations. > > 1- set policy id 1000 from "Untrust" to "Trust" "Any" "1.1.1.1" "HTTP" nat > dst ip 10.10.10.10 port 8000 permit log > > 2- set policy id 5000 from "Trust" to "U

Re: Python re to extract useful information from each line

2015-04-29 Thread Tim Chase
On 2015-04-29 14:22, Emile van Sebille wrote: > On 4/29/2015 1:49 PM, Kashif Rana wrote: > > pol_elements = > > re.compile('id\s(?P.+?)(?:\sname\s(?P.+?))?\sfrom\s(?P.+?)\sto\s(?P.+?)\s{2}(?P[^\s]+?)\s(?P[^\s]+?)\s(?P[^\s]+?)(?:(?P\snat)\s(?P[^\s]+?)(?P\sdip-id\s[^\s]+?)?)?\s(?P[^\s]+?)(?:\sschedul

Re: Python re to extract useful information from each line

2015-04-29 Thread Mark Lawrence
On 29/04/2015 22:22, Emile van Sebille wrote: On 4/29/2015 1:49 PM, Kashif Rana wrote: pol_elements = re.compile('id\s(?P.+?)(?:\sname\s(?P.+?))?\sfrom\s(?P.+?)\sto\s(?P.+?)\s{2}(?P[^\s]+?)\s(?P[^\s]+?)\s(?P[^\s]+?)(?:(?P\snat)\s(?P[^\s]+?)(?P\sdip-id\s[^\s]+?)?)?\s(?P[^\s]+?)(?:\sschedule\s(?P[

Re: Python re to extract useful information from each line

2015-04-29 Thread MRAB
On 2015-04-29 22:22, Emile van Sebille wrote: On 4/29/2015 1:49 PM, Kashif Rana wrote: pol_elements = re.compile('id\s(?P.+?)(?:\sname\s(?P.+?))?\sfrom\s(?P.+?)\sto\s(?P.+?)\s{2}(?P[^\s]+?)\s(?P[^\s]+?)\s(?P[^\s]+?)(?:(?P\snat)\s(?P[^\s]+?)(?P\sdip-id\s[^\s]+?)?)?\s(?P[^\s]+?)(?:\sschedule\s(?P

Re: Python re to extract useful information from each line

2015-04-29 Thread Emile van Sebille
On 4/29/2015 1:49 PM, Kashif Rana wrote: pol_elements = re.compile('id\s(?P.+?)(?:\sname\s(?P.+?))?\sfrom\s(?P.+?)\sto\s(?P.+?)\s{2}(?P[^\s]+?)\s(?P[^\s]+?)\s(?P[^\s]+?)(?:(?P\snat)\s(?P[^\s]+?)(?P\sdip-id\s[^\s]+?)?)?\s(?P[^\s]+?)(?:\sschedule\s(?P[^\s]+?))?(?P\slog)?$' ) ... and that's why

Re: Python re to extract useful information from each line

2015-04-29 Thread Kashif Rana
On Thursday, April 30, 2015 at 12:42:18 AM UTC+4, Kashif Rana wrote: > Hello Experts > > I have below lines with some variations. > > 1- set policy id 1000 from "Untrust" to "Trust" "Any" "1.1.1.1" "HTTP" nat > dst ip 10.10.10.10 port 8000 permit log > > 2- set policy id 5000 from "Trust" to "U

Python re to extract useful information from each line

2015-04-29 Thread Kashif Rana
Hello Experts I have below lines with some variations. 1- set policy id 1000 from "Untrust" to "Trust" "Any" "1.1.1.1" "HTTP" nat dst ip 10.10.10.10 port 8000 permit log 2- set policy id 5000 from "Trust" to "Untrust" "Any" "microsoft.com" "HTTP" nat src permit schedule "14August2014" log 3-